Python Exercise 3
Python Exercise 3
3
1. Write a program to check the largest among the three given numbers
# Program to find the largest among the three numbers
x = int(input(‘Enter the first number: ‘))
y = int(input(‘Enter the second number: ‘))
z = int(input(‘Enter the third number: ‘))
if (x>y) and (x>z):
large = x
elif (y>x) and (y>z):
large = y
else:
large = z
print(f “The largest among {} {} { } is {}’.format(x,y,z,large))
1
5. Program to find the sum of digits in a given number
# A program to find the sum of digits of a given number
num = int(input(‘Enter the number : ‘))
summation = 0
reminder = 0
while num!= 0:
remainder = num%10
summation = summation + reminder
num = int(num/10)
print(f’The sum of digits in the number {num} is {summation}’)
if num < 0 :
print('Factorial not defined for negative numbers')
elif num == 1:
print('Factorial of one is 1')
else:
for i in range(2,num+1):
fact = fact*i
print(f' Factorial of number {num} is {fact}')