- Python
- Language
- Hello World
- Variables
- Functions
- Conditional
- Operators
- While ♣
- Turtle
- Script Mode
- Debugging
- Strings
- Slice
- Raw Strings
- Validation
- Config
- Security
- Collections
- Lists
- Dictionaries
- Efficiency
- Tree
- Iterator
- Tuples
- References
- Functions
- Recursion
- Factorial
- Modulus
- Reassignment
- Approximate
While
You can almost read while statement as if it were English.
# While syntax:
#
# You can almost read while statement as if it were English:
# - while n is greater than 0
# - display n
# - then decrement it
#
# The syntax is similar to a function definition.
def countdown(n):
while(n > 0):
print(n)
n = n -1
countdown(5) # 5 4 3 2 1
Input
Sometimes you want to take input from user until they type quit.
while True:
line = input('> ')
if (line == 'quit'):
break
print(line)
print('Done')
Last update: 61 days ago