user7433120 user7433120 - 4 years ago 73
Python Question

How could I constantly add user input to a string without using lists, dictionaries, or sets?

I have a program that prompts the user for a guess on a guessing game, and I need the program to keep the values stored some how in order to prevent the user from guessing again.

For instance if a user inputs 'a' for the first guess and 'b' for the second, I need the program to store these and tell tell the user that they have already been used.

Guesses are always single characters. I am not allowed to use lists, dictionaries, or sets.

I know that i should concatenate the strings, but other than I'm clueless. I want to use a if statement or a function but not sure how to set those up.

I am also thinking that i need something like

variable += variable
. Any tips?

Answer Source

As mentioned in the comments, you should really be using a set. Here's how to do it with string concatenation though.

guesses = ""
guess = input("guess: ")
if guess in guesses:
    print("already used")
else:
    guesses += guess
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download