Quantcast
Channel: How do I make the for loop work only if one or more items != 'yes' - Stack Overflow
Browsing latest articles
Browse All 8 View Live

Answer by a_r for How do I make the for loop work only if one or more items...

Assuming you are iterating 4 times (using range(4))based on the length of user, what you can simple do is the following: if 'n' or 'no' in user: print('Sorry, but you can\'t join our club')...

View Article



Answer by Arafat Khan for How do I make the for loop work only if one or more...

I would suggest storing your questions in a list and using a for loop to ask them. Store the user's response to another list and check if there is any "n" in this list. See code below:questions = ["Are...

View Article

Answer by Trenton McKinney for How do I make the for loop work only if one or...

Comments on OP main():A key point of programming, is code use efficiency.Don't repeatedly call functions (e.g. input and print) when not necessary.There are several ways your problem can be solved.The...

View Article

Answer by John Gordon for How do I make the for loop work only if one or more...

The usual ways to do this are a for loop with a break and an else clause:for answer in user: if answer != 'y': print('Sorry') breakelse: print('Congratulations')Or the any() function:if any(answer !=...

View Article

Answer by jottbe for How do I make the for loop work only if one or more...

there are some small points in your code that need to be changed:# Purpose: Create a fake club that has certain requirements, ask user to# fill out the application, and print out their answers +...

View Article


Answer by Alex for How do I make the for loop work only if one or more items...

There are a few ways to do this:Use a flag variable and just output at the end. (Slightly inefficient if the first response is a no)Use a flag variable and a while loop to exit as soon as the user...

View Article

Answer by ToughMind for How do I make the for loop work only if one or more...

If one "no" means decline, you can add break to exit the loop after print decline info. Just like:for i in range(4): if user[i] != 'y': print('Sorry, but you can\'t join our club') justToShowInCMD =...

View Article

How do I make the for loop work only if one or more items != 'yes'

I'm working on a HW assignment where I create a fake club with entry questions. If any of the questions are answered with "no", then the person isn't allowed to join.I've tried going back to the og...

View Article

Browsing latest articles
Browse All 8 View Live




Latest Images