Ask coding questions

← Back to all posts
While Loop in Python
MasonErbini (20)

Every time I try this, it tells me that there is an error because main is not defined. How do I fix this?

Comments
hotnewtop
Raphtalia (71)

put the while loop underneath the main() function

MasonErbini (20)

It says Line 3, The i is not defined, How do I fix [email protected]

Raphtalia (71)

@MasonErbini define i outside of the function, i is a local variable for that function

MasonErbini (20)

Thank you, you fixed my problem, but now I have another problem. It now only says Hi, I am Anthony once. Can I make it go more than once? @Raphtalia

Raphtalia (71)

@MasonErbini i is set to 1 which means it loops once, change it to the number of times you want it to loop

MasonErbini (20)

Ok, I changed it to five, but that didn't change anything. Do I have to make a while loop with the "print("Hi! I am Anthony, Talk to me!\n ")"
@Raphtalia

Raphtalia (71)

@MasonErbini put the print and user input (you =) inside the while loop