Computer Science, asked by sakshi2232, 9 months ago

Write a program using while loop that asks the user for a number, and prints a countdown from that number to zero.

Answers

Answered by Anonymous
4

write a python program using a while loop that asks the user for a number and prints a countdown from that number to zero. +4. +2. Write a python program using a while loop that asks the user for a number and prints a countdown from that number to zero.num = input (“Enter the number”) while (num > = 1) : print (“num = “, num) num – num-1 print (“Finish”)Read more on Sarthaks.com - https://www.sarthaks.com/133900/write-program-using-while-loop-that-asks-user-number-prints-countdown-from-that-number-zero

Answered by NirmalPandya
10

'''python program using while loop that asks the user for a number,

and prints a countdown from that number to zero. '''

number = int(input('Enter number: '))

while number >= 0:

   print(number)

   number -= 1

  • Create a variable of integer type and input the number from user
  • Take the condition of while to be >=0 as 0 is also to be printed
  • Inside the loop we first print the number then reduce it by 1
  • On last iteration we get number = 0 which will be printed and then the value of number = -1 which fails the while condition halting the loop and ending the program.while condition
Similar questions