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

python basic code

The document contains Python programs for various tasks: checking if a year is a leap year, determining if a number is divisible by 3 and returning its square, checking if a number is divisible by both 2 and 5, and finding the smallest of three entered numbers. Each program includes input prompts and outputs demonstrating their functionality. The examples illustrate the expected behavior for different inputs.

Uploaded by

kumargourabh101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python basic code

The document contains Python programs for various tasks: checking if a year is a leap year, determining if a number is divisible by 3 and returning its square, checking if a number is divisible by both 2 and 5, and finding the smallest of three entered numbers. Each program includes input prompts and outputs demonstrating their functionality. The examples illustrate the expected behavior for different inputs.

Uploaded by

kumargourabh101
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Write a python program to check the entered year is leap

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

Enter a Year: 2016


year is a leap year
Write a program to check the entered number is
divisible by 3 or not? If divisible return the square of
the number.

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

enter the second number: 31

enter the third number: 2


n3 is smallest number 2.0

You might also like