Advertisement
LuciusVerinus

Untitled

May 25th, 2022
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import random
  2. import types
  3.  
  4. name = input('Hello what is your name?')
  5. print('Hello ' + name)
  6. print('Shell we play a game? Please try to guess what number between (0 - 20) I am thinking about, you have 6 tries.')
  7. number = random.randint(0, 20)
  8. print()
  9.  
  10. i = 1
  11.  
  12. for i in range(1, 7):
  13. userNumber = input('Take a guess')
  14. if type(userNumber) != int: #This line is my main issue, if I delete it code works like a charm.
  15. break
  16. elif int(userNumber) > int(number):
  17. print('No! Your number is too high. Try again')
  18. elif int(userNumber) < int(number):
  19. print('No! Your number is too low. Try again')
  20. else:
  21. break
  22.  
  23. if type(userNumber) != int: #This line is my main issue, if I delete it code works like a charm.
  24. print('This is not a number')
  25. elif int(userNumber) == int(number):
  26. print('Congrats! You have guessed the number!')
  27. else:
  28. print('Sorry Mate, you have tried 6 times already, my number was ' + str(number))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement