You are on page 1of 3

NAME: CHAKKILAM TARUN SIDDARDHA

REG NO: 21MIC7027

ASSIGNMENT-3
SWE1004-INTRODUCTION TO PROGRAMMING IN PYTHON

1) Write a Python program to find whether the given number is Even or


Odd  
CODE:
num = int(input("Enter a number: "))
if num % 2==0:
    print(f"Given number {num} is even number")
else:
    print(f"Given number {num} is odd number")

OUTPUT:

2) Write a Python program to calculate the sum of three given numbers

CODE:

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


num_2 = int(input("Enter another number: "))
num_3 = int(input("Enter another number: "))
sum = num_1+num_2+num_3
print(f'The sum og given numbers {num_1} , {num_2} and {num_3} is {sum}')

OUTPUT:
3) Write a Python Program to Find the Factorial of a Number

CODE:

num = int(input("Enter the number that you wanted to find the factorial :
"))
factorial = 1
if num == 0 or num == 1 :
    print(f"The factorial of {num} is 1")
elif num <0:
    print(f"Factorial for the {num} doesn't exist")
else:
    for i in range(1 , num+1):
        factorial = i*factorial
    print(f"Factorial of {num} is {factorial}")

OUTPUT:

4) Write a Python Program to print maximum of 3 numbers 

CODE:

num_1 = int(input("Enter first number: "))


num_2 = int(input("Enter second number: "))
num_3 = int(input("Enter third number: "))
if num_1>=num_2 and num_1>=num_3:
    large = num_1
    print(f'Maximum of given three numers is {large}')
elif num_2>=num_1  and num_2>=num_3:
    large = num_2
    print(f'Maximum of given three numers is {large}')
else:
    large = num_3
    print(f'Maximum of given three numers is {large}')
   
   
   
OUTPUT:

5) Write a Python program to find whether the number is a prime or not

CODE:

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


if n>1:
    for i in range(2,n):
        if (n % i) == 0:
            print(f"Given number {n} is not a prime number")
            break
    else:
        print(f"Given number {n} is a prime number")
else:
    print(f"Given number {n} is not a prime number")  

OUTPUT:

You might also like