samedi 25 avril 2020

How could I make a limite numbres in an input and making them numbers only, I dont want symbols

I have a little game, which it let you to choose a random game, but I have three problrems:

1- I want to make my input accept only numbers, and there is no symbols.

2- I want to limit the input to be from number 0 to number 20.

3- I want to make a loop that if a the user insert a number and weither he win loose, I want to let him play again.....(it could be by asking him or directly)

Here is my code, if there is any problem(s) or reccommend(s) please tell me, and I hope that you could write it all in one letter so I could understand it, thank you very much for your help.

Here is the code:

import random
rn = int(random.randint(0, 20))
gn = int(input("write a number from 0-20: "))


while True:
  if rn < gn:
    print("You were too close, try again")
    break
  elif rn == gn:
    print("Oh, I lost, you win, good game (GG)")
    break
  if rn > gn:
    print("You are not close, try again")
    break

while False:
  rn = int(random.randint(0, 20))
gn = int(input("write a number from 0-20: "))



Aucun commentaire:

Enregistrer un commentaire