-
Notifications
You must be signed in to change notification settings - Fork 42
/
while-loops.py
28 lines (22 loc) · 1.19 KB
/
while-loops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# ------------------------------------------------------------------------------------
# Tutorial: While Loops in Python
# ------------------------------------------------------------------------------------
# Here we will look into how to use one of the loops - while loop to generate desired outputs with certain condition
# Syntax: After while we pass the condition to be checked
t = 0
while t < 10:
t = t + 2
print(t)
# Also we can use an |else| stance with the while loop as if the condition don't satisfy and we need a last statement to be executed after the while loop is finished:
t = 0
while t < 10:
t = t + 2
print(t)
else:
print("loop finished")
# So above loop will work till the specified condition is satisfied hence will run about 5 times in this case
# ------------------------------------------------------------------------------------
# Challenge: Take a user input n and find and print the reverse of the number. Also you don't have to print trailing zeroes while reversing.
# Example: 1.) Input - 2345 , Output - 5432
# 2.) Input - 2480 , Output - 842
# ------------------------------------------------------------------------------------