python_hassan
python_hassan
Areas
Write a program to calculate average of two
numbers
x= eval(input(“enter the first number”))
y= eval(input(“enter the second number”))
print(“ave= “, (x+y)/2)
Write a program to calculate area of triangle
base = float(input('Enter the base of the triangle: '))
height = float(input('Enter the height of the triangle: '))
area = (1/2) * base * height
print('Area of triangle = ',area)
print()
Other Programs
Prime (using if)
count=0
n=int (input("Enter the number"))
for x in range (1,n+1):
if n%x==0:
count+=1
if count ==2:
print(n," is a prime number")
else:
print(n,"is not a prime number")
Factorial
def factoriall(n):
if n<=1:
return 1
else:
n=n*factoriall(n-1)
return n
n =int(input("Enter the number: "))
print ("The Factorial of ",n,"is",factoriall(n))
Even & Odd
else:
print ("The number is Odd ")
Max & Min
l= [2,5,6]
maximum= max(l)
print ("the maximum number is :",maximum)
minimum= min(l)
print ("the minimum number is :",minimum)
Sqrt:
l= [2,5,6]
for x in l:
sqrt = x ** 0.5
print("square root:", sqrt)