I am trying to compare digits of a string to other digits of another string. guess_str is my input turned into a string and then num_str is the randomly generated number turned into a string.
Example:
guess_str: 100
num_str: 201
How can I have it compare the two strings so that when I type 100 as guess_str it will compare to
num_str showing that the number "1" that was input is part of num_str but not in the same spot?
In this I am wondering only about the second elif statement.
num = random.randint(100,999)
attempts = 1
max_attempts = 10
print(main())
print(num)
while attempts <= max_attempts:
guess = int(input(f"Guess#{attempts}:\n> "))
if guess == num:
print("Hooray!! That is the correct number!")
answer = input("Enter yes or no: ")
if answer.lower() == "yes":
main()
elif answer.lower() == "no":
print("Ok have a great day!")
break
else:
guess_str = str(guess)
num_str = str(num)
for i, val in enumerate(str(num)):
if guess_str[i] == val:
print("Fermi".format(i))
elif any(x in num_str for x in guess_str):
print("Pico")
elif guess_str != num_str:
print("Bagels")
break
#adds attempt to game
else:
attempts += 1
iorval, and you only want it to execute once? It seems like that code shouldn't be in the loop at all unless I'm missing something.