Question

In: Computer Science

Write a PYTHON program that uses a while loop to prompt for 5 integers. If the...

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".

Solutions

Expert Solution

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


Related Solutions

Write a Java program called Decision that includes a while loop to prompt the user to...
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail.
Write a program that uses loops (both the for-loop and the while loop). This assignment also...
Write a program that uses loops (both the for-loop and the while loop). This assignment also uses a simple array as a collection data structure (give you some exposure to the concept of data structure and the knowledge of array in Java). In this assignment, you are asked to construct an application that will store and retrieve data. The sequence of data retrieval relative to the input is Last In First Out (LIFO). Obviously, the best data structure that can...
Write a program in PYTHON, using a while loop, that asks the user to enter the...
Write a program in PYTHON, using a while loop, that asks the user to enter the amount that they have budgeted for the month. The program should then prompt the user to enter their expenses for the month. The program should keep a running total. Once the user has finished entering their expenses the program should then display if the user is over or under budget. The output should display the monthly budget, the total expenses and whether the user...
Write a program which uses a while loop to add the following numbers: 5, 52, 31,...
Write a program which uses a while loop to add the following numbers: 5, 52, 31, and 65 and output the sum of those numbers. Your output should look like this: The sum of (list the numbers) is ( give the result). //In C language Upload a screen shot of your program and the results of running the program.
every code should be in java Program 1: Write a while loop that sums the integers...
every code should be in java Program 1: Write a while loop that sums the integers from 1 to 10, excluding 3 and 6. Print the sum. [Hint: Use logical operators] Program 2: Write a for loop that attempts to display the numbers from 1 to 10, but terminates when the control variable reaches the value 6. Program 3: Write a do...while loop that prints the integers from 10 to 0, inclusive.
Write a program that uses a while loop with a priming read to ask the user...
Write a program that uses a while loop with a priming read to ask the user to input a set positive integers. As long as the user enters a number greater than -1, the program should accumulate the total, keep track of the number of numbers being entered and then calculate the average of the set of numbers after the user enters a -1. This is a sentinel controlled-loop. Here is what a sample run should look like: Enter the...
Write a program that uses a loop to read 10 integers from the user. Each integer...
Write a program that uses a loop to read 10 integers from the user. Each integer will be in the range from -100 to 100. After all 10 integers have been read, output the largest and smallest values that were entered, each on its own line in that order. Avoiding using the max or min functions from Python, and definitely use a loop to read the integers instead of 10 input statements.
Write a Java program using using WHILE loop to find the sum of all integers between...
Write a Java program using using WHILE loop to find the sum of all integers between 200 to 250 which are divisible by 7. Sample Output: Numbers between 200 and 250, divisible by 7: 203 210 217 224 231 238 245 The sum is: 1568
1. Write Python program that use a while loop to determine how long it takes for...
1. Write Python program that use a while loop to determine how long it takes for an investment to double at a given interest rate. The input will be an annualized interest rate, and the output is the number of years it takes an investment to double. Note: The amount of initial investment can be any positive value, you can use $1. 2. Write a function def DoubleInvest(initialInvest) to perform the same functionalities as question1. Make sure to include you...
Write a C program that meets the following requirements. Uses a while loop to display the...
Write a C program that meets the following requirements. Uses a while loop to display the first 10 natural numbers (on one row, with a tab separating each number) Uses a while loop to find the sum of the second set of 10 natural numbers. Reads a user entry and displays all the natural numbers up to the user entry (on a column list with a new line separating each number). Finds and displays the sum of all natural numbers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT