Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Program 1.

Input age and check eligibility for voting

# input age
age = int(input("Enter Age : "))

# condition to check voting eligibility


if age>=18:
status="Eligible"
else:
status="Not Eligible"

print("You are ",status," for Vote.")

Program 2. Python code to find sum of two numbers

num1 = int(input("Enter first number: "))


num2 = int(input("Enter second number: "))

# finding sum
sum = num1 + num2

# printing sum
print( sum )

Program 3. Program to print maximum number using if-else

# Python program to return maximum of two numbers

# Getting input from user


num1 = int(input("Enter the first number: "))
num2 = int(input("Enter the second number: "))

# printing the maximum value


if(num1 > num2):
print(num1, "is greater")
elif(num1 < num2):
print(num2, "is greater")
else:
print("Both are equal")

Program 4. Python program to find simple interest

# Python program to find simple interest

p = float(input("Enter the principle amount : "))


r = float(input("Enter the rate of interest : "))
t = float(input("Enter the time in the years: "))

# calculating simple interest


si = (p*r*t)/100

# printing the values


print("Principle amount: ", p)
print("Interest rate : ", r)
print("Time in years : ", t)
print("Simple Interest : ", si)
Program 5. Program to find area and perimeter of a circle

# Python program to find the


# area and perimeter of circle in python

# Initialising the value of PI


PI = 3.14
# Getting input from user
R = float(input("Enter radius of the circle: "))

# Finding the area and perimeter of the circle


area = (PI*R*R)
perimeter = (2*PI*R)

# Printing the area and perimeter of the circle


print("The area of circle is", area)
print("The perimeter of circle is", perimeter)

Program 6. Python Program to Check if a Number is Odd or Even

7. num = int (input (“Enter any number to test whether it is odd or even:
“)

if (num % 2) == 0:

print (“The number is even”)

else:

print (“The provided number is odd”)

Program 7. Python program to check whether the entered character is vowel or consonant.

# taking user input


ch = input("Enter a character: ")

if(ch=='A' or ch=='a' or ch=='E' or ch =='e' or ch=='I'


or ch=='i' or ch=='O' or ch=='o' or ch=='U' or ch=='u'):
print(ch, "is a Vowel")
else:
print(ch, "is a Consonant")
Program 8. Finding largest number in a list

# Python program to find largest number in a list


# using max() function

# A list of numbers
list = [19, 10, 45, 26, 6]

# max() method returns the largest element of the list


print("Largest number of the list is:", max(list))

Program 9. Create a Simple calculator using if-elif-else statement.

num1=int(input(“Enter First Number : ”))

num2=int(input(“Enter the second number : ”))

op=input(“Enter the operator : “)

if op==’+’:

print (“Addition is : “, num1+num2)

elif op==’-‘:

print(“Subtraction is : ”, num1-num2)

elif op==’*’:

print(“Multiplication is : ”, num1*num2)

elif op==’/’:

print(“Division is “, num1/num2)

else:

print(“Wrong operator”)

Program 10. Write python program to print different list

# list of numbers.

My_List1=[1,2,3,4,5]

print(My_List1)

#List of string.

My_List2= [“Army”, “Public”, “School”, ”Bareilly”]

print(My_List2)
Program 11. Program to find the area of a rectangle.

length=float( input(“Enter the length of the rectangle : ”))

breadth=float( input(“Enter the breadth of the rectangle : ”))


area=length*breadth

print(“Area= ”, area)

Program 12. Write a python program to print cube of a number

num=int(input(“Enter a number : ”))


cube=num*num*num

print(“The cube of number is: ” , cube)

Program 13. Write a program to swap two numbers.

n1=int(input(“Enter number 1 : ”))

n2=int(input(“Enter number2 : ”))


n1, n2=n2, n1

print(“After swapping : ”, n1, n2)

You might also like