In: Computer Science
Write a PYTHON program that uses a while loop to prompt for 5 integers.
If the number is equal to 99, display "Ninety-nine", otherwise display "no-match".
If the number is equal to 75, display "Seventy-five", otherwise display "no-match".
After reading the question, I understood that there can by many different interpretations of this program. There can be a program that prints ‘Ninety-nine’ if the input is 99 and ‘no-match’ if it is not, and will print ‘Seventy-five’ if input is 75 else ‘no-match’ in a way that there will be two lines of output in every iteration, one for each check. There can also be another way like if the input is 99, ‘Ninety-nine’ is printed, ‘Seventy-five’ if it is 75, or ‘no-match’ if it is neither 75 nor 95. Here is the completed code for both type implementations. Take whichever you want. (Choose either first version or second version, not both) Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.
#code
'''
First version of the program. This will prompt and read 5 numbers
from input,
if the number is 99, 'Ninety-nine' will be printed, otherwise
'no-match' will be
printed. Similarly, if the number is 75, 'Seventy-five' is printed,
else
'no-match' is printed. So in an iteration if the input is 75, the
output
will be like below
no-match
Seventy-five
and if the input is 95, the output will be like
Ninety-nine
no-match
and if the input is any other, like 34
no-match
no-match
'''
#initializing i to 0
i=0
#looping as long as i is less than 5
while i<5:
#prompting and reading an integer
num=int(input("Enter a number:
"))
#checking if number is 99
if num==99:
#printing
'Ninety-nine'
print("Ninety-nine")
else:
#otherwise, printing
'no-match'
print("no-match")
# checking if number is 75
if num == 75:
# printing
'Seventy-five'
print("Seventy-five")
else:
# otherwise,
printing 'no-match'
print("no-match")
#updating i for next iteration
i+=1
'''
Second version of the program. This will prompt and read 5 numbers
from input,
if the number is 99, 'Ninety-nine' will be printed, otherwise if
the number is 75,
'Seventy-five' is printed, else 'no-match' is printed. So in an
iteration if the input is 75,
the output will be like below
Seventy-five
and if the input is 95, the output will be like
Ninety-nine
and if the input is any other, like 34
no-match
'''
#initializing i to 0
i=0
#looping as long as i is less than 5
while i<5:
#prompting and reading an integer
num=int(input("Enter a number:
"))
#checking if number is 99
if num==99:
#printing
'Ninety-nine'
print("Ninety-nine")
#otherwise checking if number is 75
elif num == 75:
# printing
'Seventy-five'
print("Seventy-five")
else:
# otherwise,
printing 'no-match'
print("no-match")
#updating i for next iteration
i+=1