Help Python Loops

1

I am learning to use python and there is one thing that I can not do, I want to make a loop for when I ask a question, just let me put one of these letters a, b, c, d, e that in the first run, after that ask me again which letter I want to choose, but now I can choose 5 more that is% a, b, c, d, e, f, g, h, i, j and in the next print 5 more letters and so on until I reach 25 letters.

I paste down what I have done, it works well, it does not let me put numbers or the other letters, the problem is when I put two letters (for example hj ) peta if you could help me or do it in some other way than I would like to thank you.

cuantas_frutas_coger = 5
letra = 97 #Es la letra a en ASCII
jugador = '1'
while not jugador.isalpha() or ord(jugador) > letra+cuantas_frutas_coger:
    print ('Elige una letra entre a y ', chr(letra+cuantas_frutas_coger))
    jugador = input('')

I do not know if I've explained myself well, it's a game in which you first have to take 5 letters, if you win there are 10, if you win again 15 and only that piece is missing. Thanks.

    
asked by José Antonio Boza Morales 15.12.2018 в 21:59
source

1 answer

0

Regarding the reading of data, you can do one of these two things.

  • Take only the first letter of the player's response. So, if you write "aj", the "j" would be discarded:

    while not jugador.isalpha() or ord(jugador) > letra+cuantas_frutas_coger:
        print ('Elige una letra entre a y ', chr(letra+cuantas_frutas_coger))
        jugador = input('')
        jugador = jugador[0]
    
  • Do not validate an entry that has several letters, and force the player to repeat the entry if he / she puts more than one:

    while (len(jugador) > 1 or
           not jugador.isalpha() or
           ord(jugador) > letra+cuantas_frutas_coger):
        print ('Elige una letra entre a y ', chr(letra+cuantas_frutas_coger))
        jugador = input('')
        jugador = jugador[0]
    
  • As for how the game continues, it has not been clear to me. I suppose that this data entry should be part of another loop in which the variable cuantas_frutas_coger is incremented but I do not understand with what criteria. In any case, your question was limited to data entry, right?

        
    answered by 15.12.2018 / 22:13
    source