-1

So I am writing a code and I want my input line to change the number with every guess. For example;

Enter a letter for guess #1: (take input)

Enter a letter for guess #2: (take new input)

Is there a way I can change the number after the # every time?

My code right now is

letterguess = input("Enter a letter for guess #")

I know that the input line can only take one argument, so when I try to add a , count it doesnt work. I've tried to look up functions that can help but I'm getting stuck. Any advice helps! Thanks!

A.J.
  • 1
  • 2
  • 1
    If you search in your browser for "Python string format", you'll find references that can explain this much better than we can manage here. – Prune Sep 26 '19 at 23:07

3 Answers3

0

If you put your code in a loop

count = 1
while True:
    letter_guess = input(f"Input a letter for guess #{count}")
     # do something ...
     count = count + 1
Jamil Seaidoun
  • 949
  • 1
  • 11
  • 24
0

you can try a for loop and place all the desired code inside it

for i in range(3):
letterguess = input(f"Enter a letter for guess {i}#")

where placing an f infront of a string makes it a formatted string that will let you put variables inside

karimkohel
  • 96
  • 1
  • 8
0

Instead of ,count you could format like this:

letterguess = input("Enter a letter for guess #%d" % count)

Pretzel
  • 103
  • 5