Page 254 - CITS - CSA - TP (Volume 2) - Hindi
P. 254
कं ूटर सॉ वेयर ए ीके शन - CITS
टा 2: यिद-अ था कथन
कोड:
# Program to check if a number is even or odd
num = int(input(“Enter a number: “))
ifnum % 2 == 0:
print(“The number is even.”)
else:
print(“The number is odd.”)
यहां, ो ाम यह जांचता है िक िव सं ा सम है या िवषम। यिद 2 से भाग देने पर शेष 0 है, तो यह एक मैसेज ि ंट करता है जो दशा ता है िक सं ा
सम है। अ था, यह एक मैसेज ि ंट करता है जो दशा ता है िक सं ा िवषम है।
आउटपुट:
टा 3: ने ेड if कथन
कोड:
# Simple Python Program to print the largest of the three numbers.
# Taking user input for three numbers
a = int(input(“Enter a: “))
b = int(input(“Enter b: “))
c = int(input(“Enter c: “))
# Checking if ‘a’ is the largest
if a > b and a > c:
# If the condition is true, we will enter this block
print(“From the above three numbers, given ‘a’ is the largest”)
# Checking if ‘b’ is the largest
if b > a and b > c:
# If the condition is true, we will enter this block
print(“From the above three numbers, given ‘b’ is the largest”)
# Checking if ‘c’ is the largest
if c > a and c > b:
# If the condition is true, we will enter this block
print(“From the above three numbers, given ‘c’ is the largest”)
240
CITS : IT & ITES - कं ूटर सॉ वेयर अनु योग - अ ास 125

