Page 517 - Computer Science V2.0 Class 11
P. 517
Input Parameter : digit-numeric value
Return Value : digitWords
'''
digitWords = {
'0': 'zero',
'1': 'one',
'2': 'two',
'3': 'three',
'4': 'four',
'5': 'five',
'6': 'six',
'7': 'seven',
'8': 'eight',
'9': 'nine'
}
if digit in digitWords:
return digitWords[digit]
else:
return "Invalid input: Not a digit"
digit = input("Enter a numeric digit (0-9): ")
result = digitToText(digit)
print(result)
Program 25: Write a program that reads the colour of traffic light as user input in the form of a string and displays the
output as per the table given below:
Colour Output
Red STOP
Yellow Get ready
Green GO
Any other colour You have not entered the correct colour
Ans. def trafficLight(color):
'''
Objective : To display output according to traffic light color
Input Parameter : color - string
Return Value : None
'''
# Check the color and display the corresponding output
if color.lower() == "red":
print("STOP")
elif color.lower() == "yellow":
Practical 503

