PYTHON: while - a loop mechanism for iteration In Python, setting a 'while condition: block' instruction makes the computer keep executing the block while the condition is true. If the condition for looping is always true it will lead to an infinite loop. You therefore have to put in a 'break instruction'. At that point the computer starts executing whatever code follows the loop. You can do this by using the 'if: else' command.
cost = 0 items = 0 while True: Note the form of 'True' - you must put a capital letter, then lowercase for it to 'work' (be recognised as Python code)
print ("Total cost of ",items, "items ordered: £", cost)
|
|