- 1

BREAK IN LOOPS exercise question in Python

How do I solve this? Thanks. items = [] while True: n = int(input()) items.append(n) Change the code to end the loop when the user enters 0. Output the resulted list after the while loop ends. Sample Input 1 2 3 0 Sample Output [1, 2, 3]

8th Jun 2021, 7:25 AM
Frank
1 Answer
+ 4
items = [] while True: n = int(input()) if n==0: break items.append(n) print(items)
8th Jun 2021, 7:27 AM
Prashanth Kumar
Prashanth Kumar - avatar