Utkarsh – 11F
All Python Codes
Area of a circle
INPUT
‘’’r=int(input('Enter value of radius'))
print("Area-=",3.14*r*r)’’’
OUTPUT
Area = 78.2
Square et rectangle
Area and perimeter of a square
INPUT
‘’’s=float(input("Enter Side measurement"))
print("Area=", s*s)
print("Perimeter=", 4*s)’’’
OUTPUT
Enter Side measurement 20
Area= 400.0
Perimeter= 80.0
Area and perimeter of a rectangle
INPUT
‘’’l=float(input("Enter Length"))
b=float(input("Enter Breadth"))
print("Area=", l*b)
print("Perimeter", l+b)’’’
OUTPUT
Enter Length 56
Enter Breadth 52
Area= 2912.0
Utkarsh – 11F
Perimeter 108.0
Calculator
INPUT
'''print("Welcome to the calculator")
x=float(input("Enter first number"))
y=float(input("Enter second number"))
print('Addition=', x+y)
print('Subtraction=', x-y)
print('Multiplication=', x*y)
print('Division=', x/y)'''
OUTPUT
Welcome to the calculator
Enter first number 87
Enter second number457
Addition= 544
Subtraction= -370
Multiplication= 39759
Division= 0.19037199124726478
Average Marks Calculator
INPUT
'''x=int(input("Enter Marks for Accountancy"))
y=int(input("Enter Marks for Business Studies"))
z=int(input("Enter Marks for English"))
p=int(input("Enter Marks for IP"))
q=int(input("Enter Marks for Economics"))
print("Average Marks =", (x+y+z+p+q)/5)'''
Utkarsh – 11F
OUTPUT
Enter Marks for Accountancy 89
Enter Marks for Business Studies 98
Enter Marks for English 79
Enter Marks for IP 98
Enter Marks for Economics 99
Average Marks = 92.6
Item Price Calculator
INPUT
'''name=input("Enter Item name")
price=int(input("Enter Price"))
quantity=int(input("Enter Quantity"))
print("Total price -",price*quantity)''’
OUTPUT
Enter Item name Chocolate
Enter Price 10
Enter Quantity 2
Total price – 20
Celsius to Fahrenheit converter
INPUT
‘’’c=float(input("Enter Temperature in Celsius"))
f=(1.8*c)+32
print("Temperature in Fahrenheit is" ,f)'''
OUTPUT
Enter Temperature in Celsius 52
Temperature in Fahrenheit is 125.600000
Utkarsh – 11F
INR to AED and USD calculator
INPUT
‘’’inr=float(input("Enter amount in INR "))
print("AED =", round(inr/22.5,2))
print("USD =", round(inr/83.5,2))’’’
OUTPUT
Enter amount in INR 100
AED = 4.44
USD = 1.2
BMI Calculator
INPUT
‘’’h=float(input("Enter Height in meters "))
w=float(input("Enter Weight in kgs "))
print("BMI =",w/(h**2))’’’
OUTPUT
Enter Height in meters 1.7
Enter Weight in kgs 60
BMI = 20.761245674740486
Age in c years calculator
INPUT
‘’’name=input("Enter name ")
age=(input("Enter age "))
yr=2024-age+100
print(name, "turns 100 in the year", yr)’’’
Utkarsh – 11F
OUTPUT
Enter name Utkarsh
Enter age 15
Utkarsh turns 100 in the year 2109
Even and Odd numbers
INPUT
‘’’num=int(input("Enter number"))
if num % 2 ==0 :
print("It is an Even number")
else:
print(" It is an Odd number")’’’
OUTPUT
Enter number 2
It is an Even number
Enter number 3
It is an odd number
Leap year calculator
INPUT
‘’’ year=int(input("Enter year"))
if year % 4 = = 0:
print("It is a leap year")
else:
print("It is not a leap year")’’’
Utkarsh – 11F
OUTPUT
Enter year 2024
It is a leap year
Enter year 2021
It is not a leap year
Positive and negative number calculator
INPUT
‘’’n=int(input("Enter number"))
if n > 0 :
print( n ,"is a positive number")
else:
print(n , "is a negative number")’’’
OUTPUT
Enter number 5
5 is a positive number
Enter number -6
-6 is a negative number
Voting eligibility
INPUT
‘’’age=int(input("Enter your age "))
if age >= 18 :
print("You are eligible")
else:
print("You are not eligible")’’’
OUTPUT
Utkarsh – 11F
Enter your age 15
You are not eligible
Enter your age 19
You are eligible
Grade (Pass or fail) calculator
INPUT
‘’’name=input("Enter your name")
eng=int(input("Enter your english marks"))
ip=int(input("Enter your IP marks"))
bst=int(input("Enter your Business studies marks"))
accounts=int(input("Enter your Accountancy marks"))
eco=int(input("Enter your Economics marks"))
AVERAGE=(eng+ip+bst+accounts+eco)/5
if AVERAGE >= 35:
print(name, "has passed")
else:
print(name, "has failed")’’’
OUTPUT
Enter your name Utkarsh
Enter your English marks 98
Enter your IP marks 89
Enter your Business studies marks 92
Enter your Accountancy marks 90
Enter your Economics marks 85
Utkarsh has passed
Week days
INPUT
Utkarsh – 11F
’’’n=int(input("Enter day number "))
if n==1:
print("It is a Monday")
elif n==2:
print("It is a Tuesday")
elif n==3:
print("It is a Wednesday")
elif n==4:
print("It is a Thursday")
elif n==5:
print("It is a Friday")
elif n==6:
print("It is a Saturday")
elif n==7:
print("It is a Sunday")
else:
print("Wrong number") ’’’
OUTPUT
Enter day number 7
It is a Sunday’’’
Enter day number 9
Wrong number
Minutes to hours converter
INPUT
‘’’min=int(input("Enter Minutes "))
print("Hours =",min/60)’’’
OUTPUT
Enter Minutes 90
Hours = 1.5
Seconds to min converter
Utkarsh – 11F
INPUT
‘’’sec=int(input("Enter seconds "))
print("Minutes =", sec/60)’’’
OUTPUT
Enter seconds 90
Minutes = 1.5
House captains
INPUT
‘’’name=input("Enter your house name ")
if name=="summer":
print("Aaron is Summer house's captain")
elif name=="winter":
print("Praket is Winter house's captain")
elif name=="spring":
print("Mujtaba is Spring house's captain")
elif name=="autumn":
print("Neil is Autumn house's captain")
else:
print("Wrong house name")’’’
OUTPUT
Enter your house name summer
Aaron is Summer house's captain
Enter your house name utkarsh
Wrong house name
Months from numbers
INPUT
Utkarsh – 11F
‘’’n=int(input("Enter Month Number "))
if n==1:
print("Month is January")
elif n==2:
print("Month is February")
elif n==3:
print("Month is March")
elif n==4:
print("Month is April")
elif n==5:
print("Month is May")
elif n==6:
print("Month is June")
elif n==7:
print("Month is July")
elif n==8:
print("Month is August")
elif n==9:
print("Month is September")
elif n==10:
print("Month is October")
elif n==11:
print("Month is November")
elif n==12:
print("Month is December")
else:
print("Invalid Number")’’’
OUTPUT
Enter Month Number 12
Month is December
Enter Month Number 15
Invalid Number
Discount calculator
INPUT
‘’’ amt=float(input("Enter amount"))
dis=0
if amt>=10000:
dis=0.20*amt
total=amt-dis
elif amt>=5000 and amt<1000:
dis=0.15*amt
total=amt-dis
elif amt>=1000 and amt<5000:
dis=0.10*amt
Utkarsh – 11F
total=amt-dis
elif amt<1000:
total=amt
print("Total = ", total)’’’
OUTPUT
Enter amount 14000
Total = 11200.0
Total salary calculator
INPUT
‘’’name=input("Enter your name")
basic=int(input("Enter your basic salary"))
hra=basic*0.25
trp=basic*0.10
ea=basic*0.10
total=basic+hra+trp+ea
print(name,"your total salay is ",total)’’’
OUTPUT
Enter your name Utkarsh
Enter your basic salary 15000
Utkarsh your total salary is 21750.0
Grade calculator
INPUT
‘’’name=input("Enter name")
mark=float(input("Enter mark"))
if mark>=90 and mark<100:
print(name,"has got 'A+'")
elif mark>=80 and mark<90:
print(name,"has got 'A'")
elif mark>=70 and mark<80:
print(name,"has got 'B+'")
elif mark>=60 and mark<70:
print(name,"has got 'B'")
elif mark>=50 and mark<60:
print(name,"has got 'C'")
elif mark<50:
print(name,"has got 'D'")
Utkarsh – 11F
else:
print("Wrong number entered")’’’
OUTPUT
Enter name Utkarsh
Enter mark 9090
Utkarsh has got 'A+'
Enter name Utkarsh
Enter mark 700
Wrong number entered
First 10 even numbers
INPUT
‘’’for i in range(2,21,2):
print(i,sep=",")’’’
OUTPUT
2
4
6
8
10
12
14
16
18
20
Accepts ‘n’ and displays all even numbers up to ‘n’
INPUT
‘’’n=int(input("Enter number"))
for n in range(2,n+1,2):
print(n,sep=",")’’’
OUTPUT
Enter number 30
2
4
Utkarsh – 11F
6
8
10
12
14
16
18
20
22
24
26
28
30
Accepts ‘n’ and displays sum of odd and even numbers till ‘n’ separately
INPUT
‘’’n=int(input("Enter number"))
se=0
so=0
for i in range(1,n+1,1):
if i%2==0:
se=se+i
else:
so=so+i
print("Sum of even = ", se)
print("Sum of odd = ", so)’’’
OUTPUT
Enter number 90
Sum of even = 2070
Sum of odd = 2025
Accepts ‘n’ and displays sum of numbers which are multiple of 3 or 5
INPUT
‘’’n=int(input("Enter number"))
s=0
for i in range(1,n+1,1):
if i%3==0 or i%5==0:
s=s+i
print(‘Sum=’, s)’’’
OUTPUT
Utkarsh – 11F
Enter number 50
Sum= 593
Accepts ‘n’ and displays factorials of ‘n’
INPUT
‘’’n=int(input("Enter number"))
factorial=1
for i in range(1,n+1,1):
factorial=factorial*i
print("Factorial of", n , "=" , factorial)’’’
OUTPUT
Enter number 20
Factorial of 20 = 2432902008176640000
Accepts ‘n’ and displays table of ‘n’
INPUT
‘’’n=int(input("Enter number"))
for i in range(1,11,1):
print(n,"x", i , "=", n*i)’’’
OUTPUT
Enter number 20
20 x 1 = 20
20 x 2 = 40
20 x 3 = 60
20 x 4 = 80
20 x 5 = 100
20 x 6 = 120
20 x 7 = 140
20 x 8 = 160
20 x 9 = 180
20 x 10 = 200
Accepts ‘n’ and displays the sum of the ‘n’
Utkarsh – 11F
INPUT
n=int(input("Enter number :"))
s=0
for i in range(1,n+1):
s=s+i
print("The sum is :", s )
OUTPUT
Enter number :3
The sum is : 6
Armstrong Number
INPUT
‘’’number = int(input("Enter a number: "))
str_num = str(number)
sum = 0
for digit in str_num:
sum += int(digit) ** len(str_num)
if sum == number:
print(number, "is an Armstrong number.")
else:
print(number, "is not an Armstrong number.")’’’
OUTPUT
Enter a number: 53
53 is not an Armstrong number.
Enter a number: 153
153 is an Armstrong number.
Accepts n and displays the sum of the ‘n’
INPUT
‘’’n=int(input("Enter Number :"))
s=0
for i in range(1,n+1):
s=s+i
print("The sum is :", s)’’’
OUTPUT
Enter Number :5
Utkarsh – 11F
The sum is : 15
All Keywords of Python
INPUT
‘’’import keyword
keywords = [Link]
print(keywords)’’’
OUTPUT
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await',
'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is',
'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try',
'while', 'with', 'yield']
Centimeters to Inches and Feet converter
INPUT
‘’’cm=int(input("Enter the height in centimeters:"))
inches=0.394*cm
feet=0.0328*cm
print("The length in inches",round(inches,2))
print("The length in feet",round(feet,2))’’’
OUTPUT
Enter the height in centimeters: 123
The length in inches 48.46
The length in feet 4.03
Commission calculator from salary
INPUT
‘’’name=input("Enter name")
basic=float(input("Enter basic salary"))
Utkarsh – 11F
comm=0
if basic>=50000:
comm=0.20*basic
elif basic>= 10000 and basic<50000:
comm=0.10*basic
elif basic>= 5000 and basic<10000:
comm=0.5*basic
elif basic<5000:
comm=0
total=basic+comm
print(name,"your total salary is ", total)’’’
OUTPUT
Enter name : Utkarsh
Enter basic salary 17000
Utkarsh your total salary is 18700.0
Date Format Changer
INPUT
‘’’print("Enter date in format dd/mm/yyyy")
date = input("Enter date: ")
date = [Link]("/")
print("Date in format mm-dd-yyyy: %s-%s-%s" % (date[1], date[0],
date[2]))’’’
OUTPUT
Enter date in format dd/mm/yyyy
Enter date: 08/07/2025
Date in format mm-dd-yyyy: 07-08-2025
Kilometers to Miles converter
INPUT
km = float (input ("Please enter Kilometre unit: "))
conversion_ratio = 0.621371
m = km * conversion_ratio
print ("value of Miles: ", m)
OUTPUT
Please enter Kilometre unit: 70
Value of Miles: 43.49597
Utkarsh – 11F
Palindrome number checker
INPUT
‘’’n = int(input("Enter a number: "))
num = n
rev=0
while num > 0:
rem = num % 10
rev = (rev*10) + rem
num //= 10
if rev == n:
print("It is a palindrome number")
else:
print("It is not a palindrome number")’’’
OUTPUT
Enter a number: 123
It is not a palindrome number
Enter a number: 333
It is a palindrome number
Perfect number checker
INPUT
‘’’n = int(input("Enter a number: "))
sum = 0
for i in range(1, n):
if n % i == 0:
sum += i
if sum == n:
print(n, "is a perfect number.")
else:
print(n, "is not a perfect number.")’’’
OUPUT
Enter a number: 28
28 is a perfect number.
Enter a number: 12
12 is not a perfect number.
Reverse number
INPUT
‘’’n=int(input("Enter number: "))
rev=0
Utkarsh – 11F
while (n>0):
rev=(rev*10)+n%10
n=n//10
print("Reverse of the number is:", rev)’’’
OUTPUT
Enter number: 123
Reverse of the number is: 321
Accepts n and finds sum of all even digits in n
INPUT
n = int(input("Enter number: "))
s = 0
while n > 0:
digit = n % 10
if digit % 2 == 0:
s += digit
n/=10
print("Sum of even digits:", s)
OUTPUT
Enter number: 12
Sum of even digits: 2
Utkarsh – 11F
States name and Capital
INPUT
states={}
n=int(input("Enter n"))
while n>0:
name=input("Enter name of the States")
capital=input("Enter Capital")
states[name]=capital
n=n-1
print(states)
OUTPUT
Enter n 1
Enter name of the States Gujarat
Enter Capital Ahmedabad
{' Gujarat': ' Ahmedabad'}
Contact Name and Number
INPUT
contact={}
n=int(input("Enter n"))
while n>0:
name=input("Enter name")
number=int(input("Enter number"))
contact[name]=number
n=n-1
print(contact)
OUTPUT
Enter n 1
Enter name Utkarsh
Enter number 0564139854
{' Utkarsh ': 564139854}
Country and Capital
INPUT
country={}
n=int(input("Enter n"))
while n>0:
countries=input("Enter name of the Country")
capital=input("Enter Capital")
country[countries]=capital
n=n-1
print(country)
OUTPUT
Utkarsh – 11F
Enter n 1
Enter name of the Country India
Enter Capital Delhi
{' India': ' Delhi'}
Employ Name and Number
INPUT
emp={}
n=int(input("Enter n"))
while n>0:
empno=input("Enter Employ Number")
ename=input("Enter Employ Name")
emp[empno]=ename
n=n-1
print(emp)
OUTPUT
Enter n 1
Enter Employ Number 123
Enter Employ Name Utkarsh
{' 123': ' Utkarsh'}
Student Name and Roll Number
INPUT
student={}
n=int(input("Enter Number"))
while n>0:
name=input("Enter name")
rollno=input("Enter Roll Number")
student[rollno]=name
n-1
print(student)
OUTPUT
Enter Number 1
Enter name Utkarsh
Enter Roll Number 27
{' 27': ' Utkarsh'}
Utkarsh – 11F
Accepts the list and displays sum of the list
INPUT
l=eval(input("Enter List : "))
s=0
for i in l:
s=s+i
print("Sum =", s)
OUTPUT
Enter List : [1,2,3,4,5,6]
Sum = 21
Accepts list and displays sum of even and odd numbers separately
INPUT
l=eval(input("Enter List : "))
se=0
so=0
for i in l:
if i%2==0:
se=se+i
else:
so=so+i
print("Sum of even = ", se)
print("Sum of odd = ", so)
OUTPUT
Enter List : [1,2,3,4,5,6]
Sum of even = 12
Sum of odd = 9
Accepts list and counts the numbers divisible by 7
INPUT
l=eval(input("Enter List : "))
count=0
for i in l:
if i%7==0:
count+=1
print(i,end=' ')
print("\nTotal =", count)
OUTPUT
Utkarsh – 11F
Enter List : [21,49,70,123,12,1,45]
21 49 70
Total = 3
Accepts list and displays the numbers divisible by 5 o 7
INPUT
l=eval(input("Enter list : "))
for i in l:
if i%5==0 or i%7==0:
print( i, end=" ")
OUTPUT
Enter list : [5,21,35,67,99,100]
5 21 35 100
Accepts list and displays the highest and the lowest number
INPUT
l=eval(input("Enter list : "))
print("Lowest is : ", min(l))
print("Lowest is : ", max(l))
OUTPUT
Enter list : [1,2,4,6,943,786,5433,-5]
Lowest is : -5
Lowest is : 5433
Utkarsh – 11F
Phonebook – Menu driven program
INPUT
phbook= {}
while True:
print("[Link]")
print("[Link]")
print("[Link]")
print("[Link]")
print("[Link]")
print("[Link]")
ch=int(input("Enter your choice"))
if ch==1:
name=input("Enter your name")
phone=input("Enter your phone number")
phbook[name]=phone
elif ch==2:
for k in phbook:
print(k,";", phbook[k])
elif ch==3:
name=input("Enter name to be searched")
print(phbook[name])
elif ch==4:
name=input("enter name to be removed")
prt=input("Are You sure? Y or N")
if prt=='Y':
del phbook [name]
print("Name DELETED!!!")
else:
print("Name not deleted")
elif ch==5:
name=input("Enter you name")
phone=input("Enter your phone number")
phbook[name]=phone
elif ch==6:
break
else:
print('Invalid option')
Patterns
Pattern 1 –
INPUT
for i in range(0, 5):
for j in range(0, i+1):
print("*", end=" ")
print()
Utkarsh – 11F
Pattern 2 –
for i in range(0, 4):
for j in range(4, i, -1):
print(j, end=" ")
print()
Pattern 3 –
INPUT
for i in range(0, 5):
for j in range(0, i+1):
print("*", end=" ")
print()
Inputs n and displays n*1, n*2 and n*3
INPUT
n=int(input("Enter number 'n' :"))
print("N2 =", n*2)
print("N3 =", n*3)
print("N4 =", n*4)
OUTPUT
Enter number 'n' : 2
N2 = 4
N3 = 6
N4 = 8
Swap factors
INPUT
x = input('Enter value of x: ')
y = input('Enter value of y: ')
temp = x
x = y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
OUTPUT
Enter value of x: 2
Enter value of y: 3
The value of x after swapping: 3
The value of y after swapping: 2
Utkarsh – 11F
Rank calculator
INPUT
a=int(input("Enter Accountancy mark "))
b=int(input("Enter Business studies mark "))
c=int(input("Enter Economics mark "))
d=int(input("Enter IP mark "))
e=int(input("Enter English mark "))
total=a+b+c+d+e
percent=(total/500)*100
print("Total =", total, "Percent =", percent)
if percent>=80:
print("You have got A grade")
elif percent>= 60:
print("You have got B grade")
elif percent>=40:
print("You have got C grade")
else:
print("You have got D grade")
OUTPUT
Enter Accountancy mark 90
Enter Business studies mark 80
Enter Economics mark 92
Enter IP mark 94
Enter English mark 92
Total = 448 Percent = 89.6001
You have got A grade
Sum of even numbers from 1 to 500
INPUT
soe= 0
for num in range(1, 501):
if num % 2 == 0:
soe += num
print("The sum of even numbers from 1 to 500 is:", soe)
OUTPUT
The sum of even numbers from 1 to 500 is: 62750
Utkarsh – 11F
Contact numbers
INPUT
contact = {}
n = int(input("Enter number of contacts to be added: "))
for i in range(n):
name = input("Enter name: ")
phone = input("Enter number: ")
contact[name] = phone
print(contact)
OUTPUT
Enter number of contacts to be added: 2
Enter name: Utkarsh
Enter number: 0567834502
Enter name: Allen
Enter number: 0566328453
{'Utkarsh': '0567834502', 'Allen': '0566328453'}