QUE 1
# Python program to perform Addition Subtraction Multiplication
# and Division of two numbers
num1 = int(input("Enter First Number: "))
num2 = int(input("Enter Second Number: "))
print("Enter which operation would you like to perform?")
ch = input("Enter any of these char for specific operation +,-,*,/: ")
result = 0
if ch == '+':
result = num1 + num2
elif ch == '-':
result = num1 - num2
elif ch == '*':
result = num1 * num2
elif ch == '/':
result = num1 / num2
else:
print("Input character is not recognized!")
print(num1, ch , num2, ":", result)
QUE 2
# 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)
QUE 3
celsius=int(input("Enter the temperature in celcius:"))
f=(celsius*1.8)+32
print("Temperature in farenheit is:",f)
QUE 4
principle=float(input("Enter the principle amount:"))
time=int(input("Enter the time(years):"))
rate=float(input("Enter the rate:"))
simple_interest=(principle*time*rate)/100
print("The simple interest is:",simple_interest)
QUE 5
# Reading principal amount, rate and time
principal = float(input('Enter amount: '))
time = float(input('Enter time: '))
rate = float(input('Enter rate: '))
# Calcualtion
compound_interest = principal * ( (1+rate/100)**time - 1)
print('Compound interest is: %f' %(compound_interest))
QUE 6
print("Enter the First String: ")
strOne = input()
print("Enter the Second String: ")
strTwo = input()
strThree = strOne + strTwo
print("\nConcatenated String: ", strThree)
QUE 7
print("Equation: ax^2 + bx + c ")
a=int(input("Enter a: "))
b=int(input("Enter b: "))
c=int(input("Enter c: "))
d=b**2-4*a*c
d1=d**0.5
if(d<0):
print("The roots are imaginary. ")
else:
r1=(-b+d1)/2*a
r2=(-b-d1)/2*a
print("The first root: ",round(r1,2))
print("The second root: ",round(r2,2))
QUE 8
Python Program to Calculate Distance
# Reading co-ordinates
x1 = float(input('Enter x1: '))
y1 = float(input('Enter y1: '))
x2 = float(input('Enter x2: '))
y2 = float(input('Enter y2: '))
# Calculating distance
d = ( (x2-x1)**2 + (y2-y1)**2 ) ** 0.5
# Displaying result
print('Distance = %f' %(d))
QUE 9
# Prompt the user to input the lengths of the shorter triangle sides.
print("Input lengths of shorter triangle sides:")
# Read and convert the input for side 'a' to a floating-point number.
x= float(input("a: "))
# Read and convert the input for side 'b' to a floating-point number.
y = float(input("b: "))
h = (x**2 + y**2)**0.5
print("The length of the hypotenuse is:", h)
QUE 10
Mass = int(input("Enter the Mass: "))
Acceleration = int(input("Enter the acceleration: "))
Force = Mass * Acceleration
print ("Force:", Force, "N")
QUE11
#Calculate Kinetic Energy
print("This program calculates the kinetic energy of a moving object.")
m_string = input("Enter the object's mass in kilograms: ")
m = float(m_string)
v_string = input("Enter the object's speed in meters per second: ")
v = float(v_string)
e = 0.5 * m * v * v
print ("The object has " + str(e) + " joules of energy.")
QUE 12
while (1):
print("1. Calculate Voltage")
print("2. Calculate Resistance")
print("3. Calculate Current")
print("4. Exit Program")
ask = input("> ")
if (ask == "1"):
print("-- Calculating Voltage --")
i = float(input("Current: "))
r = float(input("Resistence: "))
v=i*r
print("Voltage = ", format(v, ".2f"))
elif(ask == "2"):
print("-- Calculating Resistance --")
v = float(input("Voltage: "))
i = float(input("Current: "))
r=v/i
print("Resistance = ", format(r, ".2f"))
elif(ask == "3"):
print("-- Calculating Current --")
v = float(input("Voltage: "))
r = float(input("Resistence: "))
i=v/r
print("Current = ", format(i, ".2f"))
elif(ask == "4"):
break
else:
print("Not an option, Try again")
QUE13
m1=float(input("Enter the first mass: "))
m2=float(input("Enter the second mass: "))
r=float(input("Enter the distance between the centres of the masses: "))
G=6.673*(10**-11)
f=(G*m1*m2)/(r**2)
print("Hence, the gravitational force is: ",round(f,2),"N")
QUE 14
DIDN’T GOT
QUE15
num = int(input("Enter a Number:"))
if num % 2 == 0:
print("Given number is Even")
else:
print("Given number is Odd")
QUE 16
Didn’t got
QUE 17
sub1=int(input("Enter marks of the first subject: "))
sub2=int(input("Enter marks of the second subject: "))
sub3=int(input("Enter marks of the third subject: "))
sub4=int(input("Enter marks of the fourth subject: "))
sub5=int(input("Enter marks of the fifth subject: "))
avg=(sub1+sub2+sub3+sub4+sub4)/5
if(avg>=90):
print("Grade: A")
elif(avg>=80&avg<90):
print("Grade: B")
elif(avg>=70&avg<80):
print("Grade: C")
elif(avg>=60&avg<70):
print("Grade: D")
else:
print("Grade: F")
QUE 18
num = float(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
QUE 19
Python program to find the largest number among the three input numbers
# change the values of num1, num2 and num3
# for a different result
num1 = 10
num2 = 14
num3 = 12
# uncomment following lines to take three numbers from user
#num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3
print("The largest number is", largest)
QUE 20
Python program to find the factorial of a number provided by the user.
# change the value for a different result
num = 7
# To take input from the user
#num = int(input("Enter a number: "))
factorial = 1
# check if the number is negative, positive or zero
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)
QUE 21
n=int(input("Enter a number: "))
sum1 = 0
while(n > 0):
sum1=sum1+n
n=n-1
print("The sum of first n natural numbers is",sum1)
QUE22
#Multiplication table (from 1 to 10) in Python
num = int(input("Display multiplication table of? "))
# Iterate 10 times from i = 1 to 10
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
QUE23
# Program to check if a string is palindrome or not
my_str = 'aIbohPhoBiA'
# make it suitable for caseless comparison
my_str = my_str.casefold()
# reverse the string
rev_str = reversed(my_str)
# check if the string is equal to its reverse
if list(my_str) == list(rev_str):
print("The string is a palindrome.")
else:
print("The string is not a palindrome.")
OR
str_1 = input (“Enter the string to check if it is a palindrome: “)
str_1 = str_1.casefold ()
rev_str = reversed (str_1)
if (list str_1) == list (rev_str):
print (“The string is a palindrome.”)
else:
print (“The string is not a palindrome.”)
QUE24
num = int(input("enter the Nth term of fabonacci series ? ")
n1, n2 = 0, 1
print("Fibonacci Series:", n1, n2, end=" ")
for i in range(2, num):
n3 = n1 + n2
n1 = n2
n2 = n3
print(n3, end=" ")
print()
QUE 25
umber = 371
num = number
digit, sum = 0, 0
length = len(str(num))
for i in range(length):
digit = int(num%10)
num = num/10
sum += pow(digit,length)
if sum==number:
print("Armstrong")
else:
print("Not Armstrong")
QUE 26
num = int(input("Enter a number: "))
# define a flag variable
flag = False
if num == 0 or num == 1:
print(num, "is not a prime number")
elif num > 1:
# check for factors
for i in range(2, num):
if (num % i) == 0:
# if factor is found, set flag to True
flag = True
# break out of loop
break
# check if flag is True
if flag:
print(num, "is not a prime number")
else:
print(num, "is a prime number")
QUE 27
n=int(input("Enter number"))
sum=0
for digit in str(n):
sum=sum+int(digit)
print("Sum of digits",sum)
QUE 28
num = 1234
reversed_num = 0
while num != 0:
digit = num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
print("Reversed Number: " + str(reversed_num))
QUE29
L = [4, 5, 1, 2, 9, 7, 10, 8]
# variable to store the sum of
# the list
count = 0
# Finding the sum
for i in L:
count += i
# divide the total elements by
# number of elements
avg = count/len(L)
print("sum = ", count)
print("average = ", avg)
QUE30
The% sign is used to find the remainder when divided by another number
The remainder of such division is compared with 0
QUE 31
year = int(input("Enter a year: "))
# divided by 100 means century year (ending with 00)
# century year divided by 400 is leap year
if (year % 400 == 0) and (year % 100 == 0):
print("{0} is a leap year".format(year))
# not divided by 100 means not a century year
# year divided by 4 is a leap year
elif (year % 4 ==0) and (year % 100 != 0):
print("{0} is a leap year".format(year))
# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
print("{0} is not a leap year".format(year))
QUE 32
n=1
while n<=10:
square = n ** 2
cube = n ** 3
print ("square of", n ,"is", square)
print ("cube of" ,n ,"is", cube)
n=n+1
OR
n=1
for i in range(10):
square = n ** 2
cube = n ** 3
print ("square of", n ,"is", square)
print ("cube of" ,n ,"is", cube)
n=n+1
QUE 33
n=int(input("Enter the number of terms: "))
sum1=0
for i in range(1,n+1):
sum1=sum1+(1/i)
print("The sum of series is",round(sum1,2))
QUE 34
rows = int(input("Enter number of rows: "))
for i in range(rows):
for j in range(i+1):
print("* ", end="")
print()
QUE 35
#FOR CAPITAL ALPHABETS
rows = int(input("enter the number of rows less than or equal to 26"))
for i in range(rows):
#print characters in current line
for j in range(i + 1):
print(chr(j + 65), end="")
print()
#FOR SMALL ALPHABETS
rows = int(input("enter the number of rows less than or equal to 26"))
for i in range(rows):
#print characters in current line
for j in range(i + 1):
print(chr(j + 97), end="")
print()
FOR CASE CHOICE
case = int(input("enter 1 for uppercase and 2 for lowercase "))
rows = int(input("enter the number of rows less than or equal to 26 "))
if case == 1:
for i in range(rows):
for j in range(i + 1):
print(chr(j + 65), end="")
print()
if case == 2:
for i in range(rows):
for j in range(i + 1):
print(chr(j + 97), end="")
print()
QUE 36