Write a program to check whether a number is even or odd.
evenodd.py
num=int(input("Enter a number: "))
if(num%2==0):
print("Number is even")
else:
print("Number is odd")
Output
Question 2
Write a program to find out absolute value of an input number.
absolute.py
num=int(input("Enter a number: "))
ab=abs(num)
print("Absolute value of number is: ",ab)
Output
Question 3
Write a program to check the largest number among the three numbers.
largest.py
num1=int(input("Enter a number1: "))
num2=int(input("Enter a number2: "))
num3=int(input("Enter a number3: "))
if(num1>num2 and num1>num3):
print("Largest number is: ",num1)
elif(num2>num3 and num2>num1):
print("Largest number is: ",num2)
else:
print("Largest number is: ",num3)
Output
Question 4
Write a program to check if the input year is a leap year of not.
leapyear.py
year=int(input("Enter an year: "))
if(year%4==0):
print("This is a leap year")
else:
print("This is not a leap year")
Output
Question 5
Write a program to check if a Number is Positive, Negative or Zero.
number.py
num=int(input("Enter a number: "))
if(num==0):
print("Number is 0")
elif(num>0):
print("Number is positive")
else:
print("Number is negative")
Output
Question 6
Write a program that takes the marks of 5 subjects and displays the grade.
grade.py
mark1=int(input("Enter marks of subject1: "))
mark2=int(input("Enter marks of subject2: "))
mark3=int(input("Enter marks of subject3: "))
mark4=int(input("Enter marks of subject4: "))
mark5=int(input("Enter marks of subject5: "))
total=mark1+mark2+mark3+mark4+mark5
percent=(total*100)/500
print("Your percent: ",percent)
if(percent>=75 and percent<=100):
print("You have passed with distinction")
elif(percent>=60 and percent<75):
print("You have passed with first class")
elif(percent>=40 and percent<60):
print("You have passed with second class")
elif(percent>=0 and percent<40):
print("You have failed")
else:
print("Invalid marks")