DEV Community

Cover image for Python Loop Troubles
Brooke :3
Brooke :3

Posted on • Updated on

Python Loop Troubles

Hi, I'm fairly new to coding and I wanted to learn Python. I think it's a really fun and simple to use language. I am having a bit of trouble with this piece of code that I attached, and I also attached what it actually looks like when you compile it. What I want it to do is keep asking the user to input a response if the inputted response doesn't match the values the program can give, and it kinda works but you at the end, in the picture with the compiled code it will keep repeating its self and I don't want that. I want the loop to stop running when the it has the correct inputted response, where the program can provide an output. I've pretty much tried everything I could think of and I still cant figure it out. If anyone could help me that would be greatly appreciated!! or let me know if this isn't clear enough or something.

Top comments (5)

Collapse
 
hqloi21 profile image
QLoi

I wanted to help but I couldn't see any attachment in your post.
Would you mind edit your post?

Collapse
 
solidsnakelov3r profile image
Brooke :3

Oh I'm sorry I just edited it now thank you for telling me! I wasn't able to upload the second photo but I hope this helps!

Collapse
 
hqloi21 profile image
QLoi

There are a few problems with your code.

  1. The while condition logic is not wrong. It should be 'and' not 'or'.
  2. The if logic in the while loop is not the same as the one above it. I assume you want to run the code once, then if the choice is wrong, then you asking the user again, right? If so, what you can do is just start the while loop without condition, then break out of the loop if the user inputted the right answer.
  3. You don't need to check if the user is the right format or not. Keep the list value lower case, then just convert whatever the user inputted to lower case before checking with the list values.

I hope my answer is clear enough.

Thread Thread
 
solidsnakelov3r profile image
Brooke :3

Yes, it was very clear!! I can't thank you enough my program actually works now, thank you again and have a wonderful day!

Thread Thread
 
hqloi21 profile image
QLoi

Glad you worked it out!