python basic code
python basic code
year or not
1).INPUT:
#to check if the given year is leap year or not
year=int(input("Enter a Year: "))
if year%4==0:
print("year is a leap year")
else:
if year%400==0:
print("year is a leap year")
else:
if year%100==0:
print("year is not a leap year")
else:
print("year is not a leap year")
OUTPUT:
Enter a Year: 2007
year is not a leap year
2). INPUT:
#to check if the number is divsible by 3 or not and what is it square
x=int(input("enter a number:"))
y=x**2
if x%3==0:
print("the number is divisible by 3 and its square is:",y)
else:
print("the number is not divisible by 3")
OUTPUT:
enter a number:9
the number is divisible by 3 and its square is: 81
Write a python program to check, the entered number
is divisible by 2 and 5 both
3). INPUT:
#to check if the number is divisible by 2 and 5
a=int(input("enter a number: "))
if a%2==0 and a%5==0:
print("the number is divisible by 2 and 5 both")
else:
print("the number is not divisible by 2 and 5")
OUTPUT:
enter a number: 20
the number is divisible by 2 and 5 both
enter a number: 5
the number is not divisible by 2 and 5
Write a python program to return the
smallest of entered 3 numbers
4). INPUT:
#to check the smallest number among 3 numbers.
n1=float(input("enter the first number: "))
n2=float(input("enter the second number: "))
n3=float(input("enter the third number: "))
if n1<n2 and n1<n3:
print("n1 is smallest number ",n1)
elif n2<n1 and n2<n3:
print("n2 is smallest number ",n2)
elif n3<n1 and n3<n2:
print("n3 is smallest number ",n3)
OUTPUT:
enter the first number: 21