OUTPUT:
PROGRAM: enter the age: 46
a=int(input("enter the age: ")) the person is experienced 46
if (a>0 and a<12):
print("the person is a kid",a)
elif (a>12 and a<19):
print("the person is a teenager ",a)
elif (a>19 and a<30):
print("the person is young ",a)
elif (a>30 and a<45):
print("the person is mature ",a)
elif (a>45 and a<60):
print("the person is experienced ",a)
elif (a>60 and a<75):
print("the person is old ",a)
elif (a>75):
print("the person is senior citizen ",a)
PROGRAM: OUTPUT:
print("calculator") calculator
print(1 ,"addition") 1 addition
print(2 ,"substract") 2 substract
print(3 ,"multiplication") 3 multiplication
print(4 ,"divide") 4 divide
a=int(input("enter your first number: ")) enter your first number: 25
b=int(input("enter your second number: ")) enter your second number: 14
o=int(input("enter your choice: " )) enter your choice: 2
if o==1: a - b = 11
print("a","+","b","=",a+b)
elif o==2:
print("a","-","b","=",a-b)
elif o==3:
print("a","*","b","=",a*b)
elif o==4:
print("a","/","b","=",a/b)
PROGRAM: OUTPUT:
r=int(input("enter the radius")) enter the radius43# #
a=3.14*(r*r) area = 50.24 cm^2
print("area","=",a,"cm^2")
PROGRAM: OUTPUT:
l=int(input("enter the length: ")) enter the length: 6
b=int(input("enter the breadth: ")) enter the breadth: 4
h=int(input("enter the height: ")) enter the height: 2
a=2*(l*b+b*h+h*l) area of cuboid = 88 cm^2
print("area of cuboid = ",a,"cm^2")
PROGRAM: OUTPUT:
print("Welcome to the simple calculator") Welcome to the simple calculator
What's the first number? 25
Pick an operation:
def add(n1, n2): +
return n1 + n2 -
def sub(n1, n2): *
return n1 - n2 /
def multiply(n1, n2): +
return n1 * n2 What's the next number?:
def divide(n1, n2): 50
return n1/n2 25 + 50 : 75
n1 = int(input("What's the first number? "))
operation = str(input("Pick an operation: \n + \n - \n *
\n / \n "))
n2 = int(input("What's the next number?: \n"))
dict = {"+": add, "-": sub, "*": multiply, "/": divide}
function = dict[operation]
result = function(n1,n2)
print(f"{n1} {operation} {n2} : {result}")
calculation_finished = False
PROGRAM: OUTPUT:
size = 7 *
m = size * *
for i in range(0, size): * * *
for j in range(0, m): * * * *
print(end=" ") * * * * *
m=m-1 * * * * * *
for j in range(0, i + 1): * * * * * * *
print("* ", end=' ')
print(" ")
PROGRAM: OUTPUT:
def factorial(n): enter a number: 6
the factorial of 6 is 720
if n == 0 or n == 1:
return 1
else:
return n *factorial(n-1)
n=int(input("enter a number: "))
result=factorial(n)
print(f"the factorial of {n} is {result}")
PROGRAM: OUTPUT:
enter a number: 7
# fib1.py 0112358
def fibonacci(n):
if n<=0:
return 0
elif n==1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
import fib1
n=int(input("enter a number: "))
for i in range(n):
print(fib1.fibonacci(i), end=' ')
PROGRAM: OUTPUT:
def add(x,y): available operation are +,-,*,/
return x+y enter your operation: *
def sub(x,y): enter your first number: 10
return x-y enter your second number: 4
def prod(x,y): 40
return x*y
def div(x,y):
return x/y
print("available operation are +,-,*,/")
c=input("enter your operation: ")
a=int(input("enter your first number: "))
b=int(input("enter your second number: "))
if c == "+":
res=add(a,b)
elif c == "-":
res=sub(a,b)
elif c == "*":
res=prod(a,b)
elif c == "/":
res=div(a,b)
else:
res = None
if res is not None:
print(res)
PROGRAM: OUTPUT:
total_sticks = 16 There are 16 sticks left.
Player 1, pick 1, 2, or 3 sticks: 3
There are 13 sticks left.
while total_sticks > 0: Player 2, pick 1, 2, or 3 sticks: 2
There are 11 sticks left.
print(f"There are {total_sticks} sticks left.") Player 1, pick 1, 2, or 3 sticks: 3
player1_choice = int(input("Player 1, pick 1, 2, or 3 There are 8 sticks left.
sticks: ")) Player 2, pick 1, 2, or 3 sticks: 1
There are 7 sticks left.
Player 1, pick 1, 2, or 3 sticks: 3# #2
while player1_choice < 1 or player1_choice > 3 or There are 5 sticks left.
player1_choice > total_sticks: Player 2, pick 1, 2, or 3 sticks: 3
print("Invalid choice. You can only pick 1, 2, or 3 There are 2 sticks left.
sticks.") Player 1, pick 1, 2, or 3 sticks: 1
player1_choice = int(input("Player 1, pick 1, 2, or There are 1 sticks left.
3 sticks: ")) Player 2, pick 1, 2, or 3 sticks: 2
Invalid choice. You can only pick 1, 2, or 3 sticks.
Player 2, pick 1, 2, or 3 sticks: 3# #1
total_sticks -= player1_choice Player 2 has taken the last stick. Player 2 loses!
if total_sticks == 0:
print("Player 1 has taken the last stick. Player 1
loses!")
break
print(f"There are {total_sticks} sticks left.")
player2_choice = int(input("Player 2, pick 1, 2, or 3
sticks: "))
while player2_choice < 1 or player2_choice > 3 or
player2_choice > total_sticks:
print("Invalid choice. You can only pick 1, 2, or 3
sticks.")
player2_choice = int(input("Player 2, pick 1, 2, or
3 sticks: "))
total_sticks -= player2_choice
if total_sticks == 0:
print("Player 2 has taken the last stick. Player 2
loses!")
break
PROGRAM: OUTPUT:
def gcd(a,b): enter the first number: 24
if b ==0: enter the second number: 3# #18
return a the gcd of24 and 18 is 6
else:
return gcd(b,a % b)
num1=int(input("enter the first number: "))
num2=int(input("enter the second number: "))
result=gcd(num1,num2)
print(f"the gcd of{num1} and {num2} is {result}")
PROGRAM: OUTPUT:
num1=int(input("enter the first number: ")) enter the first number: 61
num2=int(input("enter the second number: ")) enter the second number: 25
num3=int(input("enter the third number: ")) enter the third number: 42
if num1>num2: the greatest number is: 61
if num1>num3:
print("the greatest number is: ",num1)
else:
print("the greatest number is: ",num3)
else:
if num2>num3:
print("the greatest number is: ",num2)
else:
print("the greatest number is: ",num3)
PROGRAM: OUTPUT:
#to create list [20, 45, 3, 4, 34, 3, 234]
my_list=[20,45,3,4,34,3,234] [20, 45, 3, 4, 34, 3, 234, 23]
print(my_list) [20, 45, 3, 4, 34, 3, 234, 23, 12, 445, 4543]
[20, 45, 4, 34, 3, 234, 23, 12, 445, 4543]
#too add one number [20, 45, 4, 34, 3, 23, 12, 445, 4543]
my_list.append(23) [34, 3, 23, 12, 445, 4543]
print(my_list)
#to add multiple elements
my_list.extend([12,445,4543])
print(my_list)
#to delete one element using index
my_list.pop(2)
print(my_list)
#to delete using remove
my_list.remove(234)
print(my_list)
#to delete more than one element
del my_list[:3]
print(my_list)
PROGRAM: OUTPUT:
rows = 5 11111
b=0 2222
for i in range(rows,0, -1): 333
b += 1 44
for j in range(1, i + 1): 5
print(b, end=' ')
print('\r')
PROGRAM: OUTPUT:
row=int(input("enter the number of rows for pattern: enter the number of rows for pattern: 5
")) *
for i in range (1,row+1): **
for j in range(1,i+1): ***
print("*",end="") ****
print() *****
PROGRAM: OUTPUT:
a=int(input("enter the starting number: ")) enter the starting number: 4
b=int(input("enter the ending number: ")) enter the ending number: 29
for num in range(a,b+1): 5
if num > 1: 7
for i in range(2,num): 11
if num % i ==0: 13
break 17
else: 19
print(num) 23
29
PROGRAM: OUTPUT:
l=int(input("enter the length: ")) enter the length: 8
b=int(input("enter the breadth: ")) enter the breadth: 4
a=l*b area = 32
print("area", "=",a)
PROGRAM: OUTPUT:
a=int(input("enter the first side: ")) enter the first side: 6
b=int(input("enter the second side: ")) enter the second side: 6
c=int(input("enter the third side: ")) enter the third side: 3
if a==b and b==c: the triangle is isosceles
print("the triangle is equilateral")
elif a==b or b==c or c==a:
print("the triangle is isosceles")
else:
print("the triangle is scalene")
PROGRAM: OUTPUT:
list1=list(map(int,input("enter the number with space : enter the number with space : 23 1 4 62
").split())) enter the number with space : 2 74 5 9 11
list2=list(map(int,input("enter the number with space : merged and sorted list with even number first
").split())) [2, 4, 62, 74, 1, 5, 9, 11, 23]
mergelist=list1 + list2
sortedlist=sorted(mergelist,key=lambda x: (x%2,x))
print("merged and sorted list with even number first")
print(sortedlist)
PROGRAM: OUTPUT:
first_string=input("enter the string you want: ") enter the string you want: Hello beautiful world!
second_string="additional string" Hello beautiful world!additional string
third_string=first_string + second_string the substring is = Hello be
print(third_string)
sub_string=third_string[:8]
print("the substring is = ",sub_string)
PROGRAM: OUTPUT:
n=int(input("enter your number : ")) enter your number : 4
for i in range (1,11): 4*1=4
print(n,"*",i,"=",n*i) 4*2=8
4 * 3 = 12
4 * 4 = 16
4 * 5 = 20
4 * 6 = 24
4 * 7 = 28
4 * 8 = 32
4 * 9 = 36
4 * 10 = 40