-1
f = open("CoinCount.txt","r") 
print(f.readline())
print(f.readline())
print(f.readline())
print(f.readline())

userChoice = input(" Which option would you like to open: Enter 1,2,3 or 4:")
if userChoice == "1":
    presence_check = False
    while presence_check == False:
        name = input("What is the volunteers name?:  ")
        if len(name) <1:
            print("Please enter your name again")
        else:
            print("Thank You!")
            presence_check = True




        userChoice2 = input("What is the coin type you want to count?: ")
        while userChoice2 == False:
            if userChoice2 in ["1p", "2p", "5p", "10p", "20p", "50p", "£1", "£2"]:
                print("Thank You!")
                userChoice2 == True
            else:
                userChoice2 == False


            userChoice3 = input("What is the weight of the coin bag?: ")
            if userChoice3 <= 100:
                print("You need to add some more coins to the bag")
            else:
                print("Your bag has the correct weight")

The part where the program asks for a coin type is the part I am struggling with. I don't know how to get the program to re ask the user for a coin type if an invalid one is entered.

Coding101
  • 1
  • 3
  • 1
    The `while` loop should just be around the coin type question, and you need to ask for the input again. – Barmar Jan 10 '20 at 21:37

2 Answers2

1

Try to change this line with

while userChoice2 not in ["1p", "2p", "5p", "10p", "20p", "50p", "£1", "£2"]:
    print("Wrong input")
    print("You have to pick one from "1p", "2p", "5p", "10p", "20p", "50p", "£1", "£2"")
    userChoice2 = input("What is the coin type you want to count?: ")
Jakub Swistak
  • 304
  • 3
  • 10
0

The way your code is written right now, the user will be asked for the weight of the coin bag no matter their response to the coin-type question. If you move the weight-of-the-coin-bag question outside of the while loop, the user will be asked for the coin type repeatedly until they give a response in your list.

while userChoice2 not in ['1p', '2p', ..., '£2']: userChoice2 = input('What is the coin type you want to count?:')

Josh Clark
  • 964
  • 1
  • 9
  • 17