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

Week 3

Uploaded by

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

Week 3

Uploaded by

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

Week 3:

1. Python program to find whether the given number is Even or Odd

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


if (n % 2) == 0:
print(n,"is Even number")
else:
print(n," is Odd number")

2. Write a Python program to get the difference between a given number


and 17, if the number is greater than 17 return double the absolute
difference

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


difference = a - 17
if difference > 17:
print(2 * abs(difference))
else:
print(difference)

3. Write a Python program to test whether a number is within 100 of 1000


or 2000.

n=int(input('enter any number'))

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


print('true')
else:
print('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 x value:'))
y=int(input('enter y value:'))
z=int(input('enter z value:'))
sum = x + y + z
if x == y == z:
sum = sum * 3
print('sum=',sum)

5. Python Program to Find the Factorial of a Number

import math
n=int(input('enter any number:'))
print('factorial of given number is:')
print(math.factorial(n))

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

factorial = 1

if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial = factorial*i
print("The factorial of",num,"is",factorial)

6. Python Program to print maximum of 3 numbers

a=int(input('enter a value:'))
b=int(input('enter b value:'))
c=int(input('enter c value:'))
if ((a >= b) and (a >= c)):
largest = a

elif ((b >= a) and (b >= c)):


largest = b
else:
largest = c

print(largest, 'is biggest number')


7. Write a python program to find whether a given year is leap or not.

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


if((Year % 400 == 0) or (Year % 100 != 0) and (Year % 4 == 0)):
print("Given Year is a leap Year");
else:
print ("Given Year is not a leap Year")

You might also like