Created
September 6, 2018 13:14
-
-
Save pknowledge/346dd48fb84275581c16d12e867ef565 to your computer and use it in GitHub Desktop.
while Loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Tutorial for Beginners - while Loop | |
#--------- Example 1 --------------- | |
i = 0 | |
while True: | |
print("the value of i is : ", i) | |
i += 1 # i = i + 1 | |
else: | |
print("Finished while loop") | |
#--------- Example 2 --------------- | |
num = 1 | |
sum = 0 | |
print("Enter a Number. Please Enter zero(0) to exit") | |
while num != 0: | |
num = float(input("Number ? ")) | |
sum = sum + num; | |
print("sum = ",sum) | |
else: | |
print("Finished sum") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment