Feb-07-2021, 02:40 AM
I'm doing my GCSE OCR 20 hour coding task and have been told to just spend 20 hours on one of the 4 topics we could choose from. I chose to pick a 2 player dice game and am currently developing a way to authorise the 2 players, but am running into a problem to do with while loops. I'm really new to coding so there's probably a really straight forward answer, but I've been searching for upwards of 30 minutes and could not find a solution. I get the desired outcome if I enter something that's meant to be invalid, but then the same outcome for something that's meant to be right. This is my code:
The only thing I am asking of help here is a way to get the correct output for entering a correct answer, e.g. whats in the list
whitelist = ["1", "2"] A = 0 B = 5 while 'inputplayer1' not in whitelist: A += 1 inputplayer1 = input("Player 1, please enter your name: ").lower() if 'inputplayer1' in whitelist: print("Player 1 is now authorised") found = True elif A == B: print("You ran out of attempts") break else: if 'inputplayer1' not in whitelist: print("Invalid username; please try again.")As I said above, not matter what I enter, even if it is in the list, I get the response "Invalid username; please try again.".
The only thing I am asking of help here is a way to get the correct output for entering a correct answer, e.g. whats in the list