What is the result of this program fragment, if the original input values are -15 for hours and 10.0 for rate (when you meant to enter 15 and 10)? hours = int(input('Enter hours worked: ')) rate = float(input('Enter pay rate in dollars per hour: ')) while hours < 0 or rate < 0: print ('Error, both values must be positive numbers. Please reenter') pay = hours * rate print('Your gross pay is ', pay)

Respuesta :

Answer:

  • The above program will gives nothing for the input value 15 and 10.
  • The loop runs infinite for the input value of -15 and 10 and every time it prints the printed statement with the value of -150 for pay variable.

Explanation:

  • The above code has a while loop which condition will always true if the first iteration of the loop condition will true.
  • It is because there is no operation in the loop body which creates a loop condition to be false after some finite amount of time.
  • When the user inputs 15 and 10 then it will not enter the loop because the loop condition will true for the less value of 0.
  • But when the user inputs -15 for the hour, then the loop condition will true for the first time and it will not be false for any iteration of the loop.
ACCESS MORE