About Me

My photo
Vijayapur, Karnataka, India
I am interested in Teaching.

Python Scripts

# Python script to find area of circle 

r=float(input("Enter the radius of a circle"))

area=3.142*r*r

print("Area of circle is",area)



 #Python script to perform arthmetical operations

a=int(input("Enter first value"))

b=int(input("Enter second value"))

add=a+b

sub=a-b

mul=a*b

div=a/b

print("Addition is",add)

print("Subtraction is",sub)

print("Multiplication is",mul)

print("Division is",div)

print("Thanking You")


#Python script to find largest of wo integers
a=int(input("Enter first number"))
b=int(input("Enter second number"))
if (a>b):
    ans=a
if(b>a):
    ans=b
print("Largest number is",ans)

#Python script to find largest of wo integers
a=int(input("Enter first number"))
b=int(input("Enter second number"))
if (a>b):
    print("Largest number is",a)
if(b>a):
    print("Largest number is",b)

#Python script to find largest of wo integers using if only once
a=int(input("Enter first number"))
b=int(input("Enter second number"))
large=a
if (b>large):
    large=b
print("Largest number is",large)

#python code to print 1 to n numbers.
n=int(input("Enter n "))
i=n
while(i>=1):
    print(i)
    i=i-1
print("Thank You")

#Python code to illustrate if else python to find largest of two nos
a=int(input("Enter furst number"))
b=int(input("Enter second number"))
if(a>b):
    print("Largest no is",a)
else:
    print("Largest number is",b)
print("Thank You")

#Python code to illustrate if else python 
uname=input("Enter user name")
pwd=input("Enter password")
if(uname=="Siddanth" and pwd=="123"):
    print("Login successful")
else:
    print("Invalid user name or password")
print("Thank You")

#Python script to display result based on average marks
avg=float(input("Enter yours average marks"))
if(avg>=70):
    print("Congratulations! Result: First Class with Distinction")
elif (avg>=60):
    print("Result: First Class")
elif (avg>=50):
    print("Result: Second Class")
elif (avg>=35):
    print("Result: Pass")
elif (avg>=0):
    print("Result: FAIL")
else:
    print("Invalid Input")
print("Thank You")

#Python script to find largest of 3 nos using nested if
a=int(input("Enter 1st number"))
b=int(input("Enter 2nd number"))
c=int(input("Enter 3rd number"))
if (a>b):
    if(a>c):
        print(a)
    else:
        print(c)
else:
    if(b>c):
        print(b)
    else:
        print(c)
print("Thank You")

#python script to print "Very good Evening" 10 times
i=1
while(i<=100):
    print("A very good evening")
    i=i+1
print("Thank You")



#Python script to print 0 to 10 intergers
for i in range(11):
    print ("A very good evening")
    


#Python script to swap two values using temporary variable
a=int(input("Enter a value"))
b=int(input("Enter b value"))
print("Before Swap")
print("a=",a," b=",b)
temp=a
a=b
b=temp
print("After Swap")
print("a=",a," b=",b)

#Python script to swap two values without using temporary variable
a=int(input("Enter a value"))
b=int(input("Enter b value"))
print("Before Swap")
print("a=",a," b=",b)
a=a+b
b=a-b
a=a-b
print("After Swap")
print("a=",a," b=",b)

#Python script to check for palindrome or not
n=int(input("Enter a number to be checked for palindrome or not"))
temp=n
rev=0
while(n!=0):
    rem=n%10
    rev=(rev*10)+rem
    n=n//10
if(rev==temp):
    print("Palindrome")
else:
    print("Not Palindrome")

#Python script to check for leap year or not leap year
y=int(input("Enter year to be checked"))
if ((y%4==0 and y%100!=0) or (y%400==0)):
    print(y," is a leap year")
else:
    print(y, " is not leap year")

#Python script to check for armstrong number or not
n=int(input("Enter a number to be checked for armstrong number or not"))
temp=n
sum=0
while(n!=0):
    rem=n%10
    sum=sum+(rem*rem*rem)
    n=n//10
if(sum==temp):
    print("Armstrong Number")
else:
    print("Not Armstrong Number")


#Python script to calculate x raised to n
x=int(input("Enter x"))
n=int(input("Enter n"))
ans=pow(x,n)
print("x ^ n   =", ans)


# Python scrpt to find sqaure root of n
import math
n=int(input("Enter a number to its square root"))
ans=math.sqrt(n)
print("Sqaure root is", ans)


#Python scrpt to check for prime number or not prime number
n=int(input("Enter number to be checked"))
for i in range(2,n//2):
    if (n%i==0):
        print(n, "is not prime number")
        exit()
print(n, "is prime Number")

#Python script to find area of triangle by reading 3 sides of it. 

import math

a=int(input("Enter the length of side a:"))

b=int(input("Enter the length of side a:"))

c=int(input("Enter the length of side a:"))

s=(a+b+c)/2

area=math.sqrt(s*(s-a)*(s-b)*(s-c))

print("Area of traingle is",area)

print("Area of traingle is","{:.2f}".format(area))


Output:

Enter the length of side a:8

Enter the length of side a:3

Enter the length of side a:9

Area of traingle is 11.832159566199232

Area of traingle is 11.83

 

#Python script to read two numbers at once

a, b = [int(a) for a in input("Input the value of a & b: ").split()]

print("The value of a & b are:",a,b)

 

Output:

Input the value of a & b: 2 4

The value of a & b are: 2 4

 


Step 1 − Make sure Python and pip is preinstalled on your system

Type the following commands in command propmt to check is python and pip is installed on your system.

To check Python

python --version

If python is successfully installed, the version of python installed on your system will be displayed.

To check pip

pip -V

The version of pip will be displayed, if it is successfully installed on your system.

Step 2 − Install Tkinter

Tkinter can be installed using pip. The following command is run in the command prompt to install Tkinter.

pip install tk

This command will start downloading and installing packages related to the Tkinter library. Once done, the message of successful installation will be displayed.

# True or False Application in Python using TKinter package.

from tkinter import *

from tkinter import messagebox as mb

main = Tk()

selected=IntVar()

main.geometry("650x450")

main.title("Flashcards by Clare")

l1 = Label(main,text="True or false",width=10,

            fg="blue",

            font=("Times New Roman",25,"bold"))

l1.pack()

l2 = Label(main,text="Is the sun a star?",width=19,fg="blue",anchor= 'w',wraplength=700,font=("Times New Roman",16,"bold"))

l2.place(x=250, y=50)

r1 = Radiobutton(

                main,

                text="True",

                value=1,

                variable=selected,

                font = ("ariel",14,"bold")

                )

r1.place(x = 150,y=100)

r2 = Radiobutton(

                main,

                text="False",

                value=0,

                variable=selected,

                font = ("ariel",14,"bold")

                )

r2.place(x = 400,y=100)

quit_button = Button(

            main, 

            text="Quit", 

            command=main.destroy,

            width=5,

            bg="white", 

            fg="black",

            font=("ariel",16," bold")

            )

quit_button.place(x=0,y=0)

def check ():

    if (selected.get()):

        mb.showinfo('Message', 'Correct answer!')

    else:

        mb.showinfo('Message', 'Wrong Answer!')

Submit_button = Button(

            main, 

            text="Submit",

            width=10,

            command=check,

            bg="#F2780C",

            fg="blue",

            font=("ariel",16,"bold")

            )

Submit_button.place(x=350,y=380)

main.mainloop()


 


No comments:

GCD of two numbers and its application...

The greatest common divisor (gcd) of two numbers is the largest positive integer that divides both numbers without leaving a remainder. The ...