0

I am trying to make a program for myself, not really related to any particular problem set.

The issue I am having is that I want a loop to iterate over a block of code and force the user to give one of two answers. If the answer isn't provided, I don't want to code to progress, and want it to again ask for input. But I also want to take a specific amount of correct answers (5 in this case) and then terminate the loop.

loops = 5
for i in range (loops):
    p = input("Input:").lower()
    if p not in ("a", "b"):
        i -= 1
        

1 Answer 1

0

Solved it!

points = 1 + self.level
            count = points + points
            while count != points:
                choice = input(f"You have {count - points} attribute points to allocate. You can level up Armor or Attack, which do you choose? ")
                choice = choice.lower()
                if choice not in ("armor", "attack"):
                    print("Try again")
                elif choice == ("armor"):
                    self.armor += 1
                    count -= 1
                elif choice == ("attack"):
                    self.attack += 1
                    count -= 1

I just added a simple counter from within the statement and changed it into a while statement. As soon as the user makes the correct choices it will increment count down so that it meets the same value as points, forcing the user to allocate all their attribute points. Kinda simple now that I wasn't overthinking it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .