0% found this document useful (0 votes)
11 views

Assignment 3

Uploaded by

vijay.23mic7015
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Assignment 3

Uploaded by

vijay.23mic7015
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Assignment – 3

Roll Number: 23MIC7015


Name of The Student:
K. VIJAY KUMAR
Slot &Date: L35+L36

1) Write a python code for determining whether a number is an odd or even number.

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

if (n%2)==0:

print(n,"is an even number")

else :

print(n,"is an odd number")

Output:
Enter a number:123456789

123456789 is an odd number

2) Write a Python program to get the difference between a given number and 17, if the
number is greater than 7 , return double the absolute difference.

a=float(input("Enter the number:"))

if (a-17)>17:

print(2*(abs(a-17)))

else:

print("Number is less than 17")

Output:

Enter the number:98

162.0
3) Write a Python program to test whether a number is within 100 of 1000 or 2000

e=int(input("Enter the number:"))

if ((abs(1000-e))<=100) or ((abs(2000-e))<=100):

print("True")

else:

print("False")

Output:
Enter the number:8

False

4) Write a Python program to calculate the sum of three given numbers, if the values are
equal then return three times of their sum

x=int(input("Enter the value of x:"))

y=int(input("Enter the value of y:"))

z=int(input("Enter the value of z:"))

sum=x+y+z

if x==y==z:

sum=sum*3

print('Sum=',sum)

else :

print("x,y,z are not equal")

Output:

Enter the value of x:1

Enter the value of y:1

Enter the value of z:1

Sum= 9
5) Write a python program to find the factorial of a number

import math

n=int(input("Enter the given number:"))

print("The factorial of the number is:",math.factorial(n))

Output:

Enter the given number:5


The factorial of the number is: 120

6) Write a python program to print maximum of 3 numbers

a=int(input("Enter the value of a:"))

b=int(input("Enter the value of b:"))

c=int(input("Enter the value of c:"))

if a>=b and a>=c:

largest=a

elif b>=c:

largest=b

else :

largest=c

print("The largest number is:",largest)

Output:

Enter the value of a:6

Enter the value of b:66

Enter the value of c:666

The largest number is: 666


7) Write a Python program to find whether a given year is a leap year or not

Year=int(input("Enter the year:"))

if((Year%400==0)or (Year%100!=0) and (Year%4==0)):

print("The given year is a leap year")

else:

print("The given year is not a leap year")

Output:

Enter the year:-40000 000000

The given year is a leap year

You might also like