226,040 views
36 votes
36 votes
In python

Write an expression that executes the loop body as long as the user enters a non-negative number.

Note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds and report "Program end never reached." The system doesn't print the test case that caused the reported message.

Sample outputs with inputs: 9 5 2 -1
Body
Body
Body
Done.

User BartusZak
by
2.4k points

1 Answer

23 votes
23 votes

Answer:

inputed = input("Choose some numbers, each separated with a space: ")

chosen = list(inputed)

chosen = chosen.remove(' ')

for value in chosen:

if '-' not in value:

print(Body)

else:

print(Done)

break

Step-by-step explanation:

The for loop will go through every value in the list (your numbers) and check if it is positive or negative.

User Anton Toshik
by
2.7k points