program
SIMPLE CALCULATOR
def add(x, y):
return x + y
def subtract(x, y):
return x y
def multiply(x, y):
return x * y
def divide(x, y):
return x / y
print("Select operation:")
print("1. Add")
print("2. Subtract")
print("3. Multiply")
print("4. Divide")
choice = input("Enter choice (1/2/3/4): ")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number : "))
if choice == '1':
print("Result:", add(num1, num2))
elif
choice == '2':
print("Result:", subtract(num1, num2))
elif
choice == '3':
print("Result:", multiply(num1, num2))
elif
choice == '4':
print("Result:", divide(num1, num2 ))
else:
print("Invalid input")
output
Select operation:
1. Add
2. Subtract
3. Multiply
4. Divide
Enter choice (1/2/3/4): 4
Enter first number: 10
Enter second number: 2
Result: 5.0
Program
Python Program to Calculate
Grade of a Student
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")
output
Enter marks of the first subject: 100
Enter marks of the second subject: 100
Enter marks of the third subject: 100
Enter marks of the fourth subject: 100
Enter marks of the fifth subject: 100
Grade: A
Program
GUESSING GAME
import random
def guessing_game():
number_to_guess = random.randint(1, 100)
guess = None
while guess != number_to_guess:
guess int(input("Guess a number between 1 and 100: ))
if guess < number_to_guess:
print("Too low!")
elif
guess > number_to_guess:
print("Too high!")
else:
print("Congratulations! You've guessed the number!")
output
Guess a number between 1 and 100: 21 Too low!
Guess a number between 1 and 100:
Program
FACTORIAL OF A NUMBER
n = int(input("Enter a number: "))
factorial = 1
for i in range(1, n + 1):
factorial *= i
print("Factorial:", factorial)
output
Enter a number: 5
Factorial: 120
Program
PALINDROME
s = input("Enter a string: ")
reverse_s = " "
for char in s:
reverse_schar + reverse_s
ifs reverse_s:
print("The string is a palindrome." )
else:
print("The string is not a palindrome.")
output
Enter a string: madam
The string is a palindrome.
Program
FIBONACCI SERIES
n = int(input("Enter the number of terms: "))
a, b = 0,1
count = 0
print("Fibonacci Series:")
while count < n:
print(a, end="")
nth = a + b
a=b
b = nth
count += 1
output
Enter the number of terms: 123
Fibonacci Series:
0,1,1,2,3,5,8,13,2,34,55,89,144,233,377,610,987,159,2584,41
81,6765,10946,17711,28657,46368,75025,121393,196418,31
7811,514229,83204,1346269,217830,3524578,5702887,9227
465,14930352,24157817,39088169,63245986,102334155,165
580141,67914296,433494437,701408733,1134903170,18363
11903,2971215073,4807526976,7778742049,12586269025,2
0365011074,32951280099,53316291173,86267571272,13958
3862445,225851433717,365435296162,591286729879,95672
2026041,548008755920,2504730781961,4052739537881,655
7470319842,10610209857723,17167680177565,2777789003
5288
44945570212853,72723460248141,17669030460994,190392
490709135, 308061521170129
Program
CALCULATE SIMPLE INTEREST
P= float(input("Enter principal amount: "))
R= float(input("Enter rate of interest: "))
T = float(input("Enter time (in years): "))
SI = (P*R*T) / 100
print(f"Simple Interest is: {SI}")
out put
Enter principal amount: 100
Enter rate of interest: 100
Enter time (in years): 10
Simple Interest is: 1000.0
Program
DECIMAL TO BINARY CONVERSION
decimal = int(input("Enter a decimal number: "))
binary = " "
while decimal > 0:
binary str(decimal % 2) + binary
decimal //= 2
print("Binary:", binary)
output
Enter a decimal number: 10
Binary: 1010
Program
MINIMUM AND MAXIMUM IN A LIST
nums = [int(x) for x in input("Enter numbers separated by
space: ).split()]
min_num = max_num = nums [0]
for num in nums:
if num min_num:
min_num = num
if num > max_num:
max_num = num
print("Minimum:", min_num, "Maximum:", max_num)
output
Enter numbers separated by space: 10 20
Minimum: 10 Maximum: 20
Program
CHECK IF NUMBER IS PERFECT
num = int(input("Enter a number: "))
sum_divisors = 0
for i in range(1, num):
if num % i == 0:
sum_divisors += i
if sum_divisors == num:
print("Perfect Number")
else:
print("Not a Perfect Number")
output
Enter a number: 496
Perfect Number
Program
REVERSE A NUMBER
num = int(input("Enter a number: "))
reversed_num = 0
while num > 0:
digit num % 10
reversed_num = reversed_num * 10 + digit
num //= 10
print("Reversed number is:", reversed_num)
output
Enter a number: 1234
Reversed number is: 4321
Program
PRINT PRIME NUMBERS
IN RANGE
start = int(input("Enter start of range : "))
end int(input("Enter end of range: ))
for num in range(start, end + 1):
if num > 1:
for i in range(2, num):
if num % i == 0:
break
else:
print(num, end="")
output
Enter start of range: 25
25/31
Enter end of range: 45
29 31 37 41 43
Program
SUM OF DIGITS OF A NUMBER
num = int(input("Enter a number: "))
sum_of_digits = 0
while num > 0:
digit num % 10
sum_of_digits += digit
num //= 10
print("Sum of digits is:", sum_of_digits)
output
Enter a number: 34678
Sum of digits is: 28
Program
MULTIPLICATION TABLE OF A NUMBER
num =int(input("ENTER ANY NUMBER= "))
for i in range(1, 11):
print(num, 'x', i, '=', num * i)
output
ENTER ANY NUMBER= 6
6*1=6
6 * 2 = 12
6 * 3 = 18
6 * 4 = 24
6 * 5 = 30
6 * 6 = 36
6 * 7 = 42
6 * 8 = 48
6 * 9 = 54
6 * 10 = 60
Program
IF A YEAR IS LEAP YEAR
year =int(input("ENTER THE YEAR= "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print("Leap year")
else:
print("Not a leap year")
output
ENTER THE YEAR 2024
Leap year