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

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.