As Python code:
again = 'yes'
while again == 'yes':
print('Hello')
again = input('Do you want to loop again? ')| Operator | Description |
|---|---|
| == | equal to |
| != | not equal to |
| > | greater than |
| < | less than |
| >= | greater or equal to |
| <= | less or equal to |
| Operator | Description |
|---|---|
| and | both conditions must be met |
| or | either condition must be met |
A WHILE loop to keep adding number until the value is 100 or more.
# 1 WHILE Loop to sum numbers up to 100
total = 0
while total < 100:
num = int(input('Enter a number: '))
total = total + num
print(f'The total is {total}')
Using a WHILE loop to verify user input
# 2 Enforcing correct user input
name = ''
while name != 'the greatest':
name = input('Who are you? ')
print(f'You are {name}!')