Python 123455
Python 123455
Compute areas of the following (Find the equation and implement in python)
1.Circle
2.Square
3.Sphere
4.Triangle
5.Rectangle
print("Menu")
print("1.CIRCLE")
print("2.SQUARE")
print("3.SPHERE")
print("4.TRIANGLE")
print("5.RECTANGLE")
a=int(input("Enter the choice: "))
if(a==1):
b=int(input("Enter the Radius of the Circle: "))
print(3.14*b*b)
elif(a==2):
c=int(input("Enter the Side of the Square: "))
print(c*c)
elif(a==3):
d=int(input("Enter the Radius of the Sphere: "))
print(4*3.14*d*d)
elif(a==4):
e=int(input("Enter the base of the triangle: "))
f=int(input("Enter the height of the triangle: "))
print(0.5*e*f)
elif(a==5):
g=int(input("Enter the length of the rectangle: "))
h=int(input("Enter the breadth of the rectangle: "))
print(g*h)
else:
print("invalid number")
Accept three sides of a triangle and print if the triangle is equilateral, isosceles or scalene.
a=int(input('Enter the side 1: '))
b=int(input('Enter the side 2: '))
c=int(input('Enter the side 3: '))
if(a==b and a==c):
print('The triangle is an equilateral triangle')
elif(a==b or b==c or c==a):
print('The triangle is an isosceles triangle')
else:
print('The triangle is a scalene triangle')
Create a calculator.
a=float(input("Enter 1st no. : "))
b=float(input("Enter 2nd no. : "))
choice=input("Enter +, -, *, /, // or % : ")
if(choice=="+"):
c=a+b
print(a,"+",b,"=",c)
elif(choice=="-"):
c=a-b
print(a,"-",b,"=",c)
elif(choice=="*"):
c=a*b
print(a,"*",b,"=",c)
elif(choice=="/"):
c=a/b
print(a,"/",b,"=",c)
elif(choice=="//"):
c=a//b
print(a,"//",b,"=",c)
elif(choice=="%"):
c=a%b
print(a,"%",b,"=",c)
else:
print("Wrong choice!")
Count the number of even and odd numbers from a series of numbers 5 to 100 using for and
range().
even_count,odd_count=0,0
x=range(5,100)
for num in x:
if num%2==0:
even_count +=1
else:
odd_count +=1
print("Even numbers in the list:",even_count)
print("Odd numbers in the list:",odd_count)
Display the Fibonacci sequence up to nth term where n is provided by the user (use while loop).
n = int(input("Enter number of terms: "))
n1,n2 = 0, 1
i=0
if n <= 0:
print("Please enter a positive integer")
elif n == 1:
print("Fibonacci sequence upto",n)
print(n1)
else:
print("Fibonacci sequence:")
while(i<n):
print(n1)
sum = n1 + n2
n1 = n2
n2 = sum
i += 1
Write a program to remove all punctuation from the string provided by the user punctuations =
'''!()-[]{};:'"\,<>./?@#$%^&*_~''‘
p='''''!()-[]{};:'"\,<>./?@#$%^&*_~'''
str=input("Enter a string: ")
c=""
for char in str:
if char not in p:
c=c+char
print(c)
Create a set, add member(s) in a set and perform following operations: intersection of sets, union
of sets, set difference, symmetric difference, clear a set.
set1 = {1, 2, 3, 4}
set1.add(5)
set1.update([6, 7, 8])
print("set1 after adding members: ", set1)
set2 = {3, 4, 5, 6}
print("intersection of set1 and set2: ", set1.intersection(set2))
print("union of set1 and set2: ", set1.union(set2))
print("set difference of set1 and set2: ", set1.difference(set2))
print("symmetric difference of set1 and set2: ", set1.symmetric_difference(set2))
set1.clear()
print("set1 after clearing all elements: ", set1)
random lottery pick. generate 100 random lottery tickets and pick two lucky ticketes
from it as a winner
import random
lottery_tickets = []
for i in range(100):
lottery_tickets.append(random.randint(1000, 9999))
winning_tickets = random.sample(lottery_tickets, 2)
print("The two lucky lottery tickets are:")
for ticket in winning_tickets:
print(ticket)
probablity of heads and tails while flipping a coin for 100 times
import random
def coin_toss(n):
heads = 0
tails = 0
for i in range(n):
result = random.randint(0, 1)
if result == 0:
heads += 1
else:
tails += 1
return heads/n, tails/n
if __name__ == '__main__':
n = 100
heads_prob, tails_prob = coin_toss(n)
print(f"The probability of getting heads is {heads_prob:.2f}")
print(f"The probability of getting tails is {tails_prob:.2f}")
remove the random name from list
import random
names = ['Alice', 'Bob', 'Charlie', 'David', 'Emily']
random_index = random.randint(0, len(names) - 1)
random_name = names.pop(random_index)
print('Removed name:', random_name)
print('Remaining names:', names)
get the same number again and again using random module
import random
random.seed(42)
print(random.random())
write a python program to print even numbers between 1 to n using while loop
start, end = 1, 100
for num in range(start, end + 1):
if num % 2 == 0:
print(num, end = " ")
Factorial
print("Enter the Number: ")
num = int(input())
fact = 1
i=1
while i<=num:
fact = fact*i
i = i+1
print("\nFactorial =", fact)
Armstrong Number
num = int(input("Enter a number: "))
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
print(num,"is an Armstrong number")
else:
print(num,"is not an Armstrong number")