Q:

Difficulty with loops

I'm having difficulty understanding loops.
Heres my problem.
Write an expression that executes the loop body as long as the user enters a non-negative number.
user_num =9;
while '"Your solution goes here"':
   print('body')
   user_num = int(input))

print ('Done.')

Can anyone help me with this and explain how loops work? 

A:

Here's a solution with some comments on each line:
user_num =9; #Initialize a random non-native number to be able to go to the core of the while loop

while (user_num >= 0): #After each user input, check if the input is a non-negative number
  #If user input is a non-negative number, you end up here, inside the while loop
  print("Body") #This is one of the statements. It prints "Body"
  user_num = int(input())  #Acquire a new input from the user and store it in the variable user_num. At this point, the loop runs again using the new user input.
#If user input doesn't meet the while loop's condition, you end up here, outside the while loop
print('Done.')

The first line, user_num = 9, acts as the user's first input. You want this number to satisfy the while loop's condition, so that it executes the statements inside of it.
Here's a good place to begin with while loops:
https://www.w3schools.com/python/python_while_loops.asp

