Unit 2 - Lesson 3

17.1.1. Understanding if-elif-else construct

ch = input("ch: ")

# write the logic to find whether the input is a character or a digit
if (ch.isdigit()):
	print("digit")
elif(ch.isalpha()):
	print("alphabet")
else:
	print("neither alphabet nor digit")

17.1.2. Write a program to check whether the given number is positive or not.

n = int(input("num: "))
if(n < 0):
	print("negative")
elif(n>0):
	print("positive")
else:
	print("zero")

17.1.3. Program to check leap year

year = int(input("year: "))
if (year%4 == 0 and year%100 != 0):
	print("leap year")
else:
	print("not leap year")

Post a Comment