Aim:
Input: A Number
Output: Print the values from given number to zero
Write a program using a while loop that asks the user for a number, and prints a countdown
from that number to zero.
Description:
A loop statement allows us to execute a statement or group of statements multiple times.
Here, We are using while loop.
while loop statement: It repeatedly executes a target statement as long as the given condition is true. The general form while statement is as follows:
while loop statement: It repeatedly executes a target statement as long as the given condition is true. The general form while statement is as follows:
while expression:
statements(s)
Here, the statement(s) may be a single a statement or a block of statements. The condition
may be any expression, and is true for any non-zero value. The loop iterates while the condition is
true. When the condition becomes false, program control passes to the line immediately following
the loop.
Algorithm:
Input: A Number
Output: Print the values from given number to zero
Step1: Start
Step2: Read num
Step3: Repeat Steps 4 and 5 while num>=0
Step4: Display num
Step5: Decrement num by 1
Step6: Stop
Program:
num=int(input("Enter number:"))
print("Countdown Starts:")
while(num>=0):
print(num)
num=num-1
Output:
Conclusion: I gets the knowledge on conditional statements and looping statements.
Python Programing Lab EXERCISE - 3(d)
netaji gandi
Sunday, June 30, 2019