0% found this document useful (0 votes)
8 views3 pages

Programs Practice

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Programs Practice

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

PYTHON FAST REVISION

_\/_________________________________\/_
_/\_________________________________/\_

python progrma list

*Addition of two numbers

number1 = float(input("Enter the first number"))

number2 = float(input("Enter the second number"))

sum = number1 +number2

print("The sum of {0} and {1} is {2}" .format(number1,number2,sum))

_________________________________________________________________________________

*python program to find maximum of 2 numbers

number1 = float(input("Enter the first number: "))

number2 = float(input("Enter the second number: "))

maximum = max(number1 , number2)

print("the maximum of {0} and {1} is {2} ".format(number1,number2,maximum))

___________________________________________________________________________________
_____

*python program to find factorial of a number using racursive

def factorial(n):
if n==0:
return 1
else:
return n* factorial(n-1)

number = int(input("Enter a numer:"))

if number < 0:
print("Factorial does not exist for negative numbers.")
elif number == 0:
print("The factorial of 0 is 1")
else:
print("The factorial of" , number , "is",factorial(number))

___________________________________________________________________________________
___

*python program to calculate simple interest

def simple_interest(principal, rate, time):


interest =(principle * rate * time) / 100
return interest

principal = float(input("Enter the principle amount:"))


rate= float(input("Enter the rate of interest:"))
time= float(input("Enter the time period(in years):"))

interest= = simple_interest(principal ,rate, time)

print("simple interest:", interest)

___________________________________________________________________________________
______

*python program to calculate compound interest

def compound_interest(principal, rate, time):


amount = principal * (pow(( 1 + rate / 100),time))
interest = amount - principal
return interest

principal = float(input("Enter the principle amount:"))


rate= float(input("Enter the rate of interest:"))
time= float(input("Enter the time period(in years):"))

interest = compound_interest(principal, rate, time)

print("Compound interest:", interest)

___________________________________________________________________________________
_____

*python program to check armstrong number

def is_armstrong(number):
num_digits = len(str(number))

sum = 0

temp = number

while temp > 0


digit = temp % 10
sum += digit ** num_digits
temp //= 10

if number == sum:
return True
else:
return False

number = int(input("enter a number: "))

if is_armstrong(number):
print(number,"is an Armstrong number")
else:
print(number,"is not an Armstrong number")

___________________________________________________________________________________
_______
*python program to find the are of the circle

radius(input("Enter the radius of the circle")


area = 3.14 * radius **2
print("The area of the circle with redius ", radius , "is" , area)

___________________________________________________________________________________
________

*python program to print all prime numbers in an interval

start = int(input("Enter the start of the interval:")


end = int(input("Enter the end of the interval:")

print("Prime numbers between", start ,"and" , end ,"are:")

for num in range(start, end +1):


if num<1:
for i in range(2, int(num**0.5) + 1)
if (num % i) == 0:
break
else:
print(num)

___________________________________________________________________________________
_______________

*python program to

You might also like