-2

I have started writing a lottery game in which the computer randomly outputs a number and then the user inputs a number, and when these two numbers do not match the computer prints('loser'). But if they do match, then it prints ('winner'). This is all well and good, until i run my code and when the user numbers = the winning numbers, it still for some reason prints out 'loser' Can someone help me with this, i know its an amatuer code but im a semi-begginer. Any help will be well appreciated. Thanks. Code:

import random
import time
r = random
print(30 * '-', 'Lottery Menu', 30 * '-')
print('Play lottery Game: 1')
print('Exit lottery game: 2')
print(74 * '-')
if input() == '1':
  print('You picked to play(1)!')
  f1 = input('enter a number between 1 and 10: ')
  print('your number = ', f1)
  time.sleep(1)
  randint = random.randint(1, 10)
  print('winning number =', randint)
 if f1 == randint:
    print('winner')
 else:
        print('Loser')
else:
print('you exited lottery menu.........')
D-python
  • 3
  • 2
  • `f1` is a string, `randint` is an int. Those two are never equal. – Adam Smith Oct 08 '20 at 02:41
  • You need to convert `f1` to `int` by doing `int(f1)`. You can also convert directly the input like: `f1 = int(input("Enter..."))`. For future questions share the error and it will be more easy to solve the problem – Jorge Morgado Oct 08 '20 at 02:42
  • 2
    [Duplicate](https://www.google.com/search?q=site%3Astackoverflow.com+python+input+is+never+equal+to+number) of [Python input never equals an integer](https://stackoverflow.com/q/39775273/4642212). Related: [How can I read inputs as numbers?](https://stackoverflow.com/q/20449427/4642212). You’re doing it correctly at `input() == '1'`. – Sebastian Simon Oct 08 '20 at 02:51
  • The answers already address your main point; as additional feedback, you should use [`secrets`](https://docs.python.org/3/library/secrets.html) rather than `random` for a lottery. The `random` module is for simulations and the like, not for situations with a (potentially) motivated adversary, – Jiří Baum Oct 08 '20 at 02:55

1 Answers1

1

Actually, f1 is a string, not an integer. While inputting, make it an integer:

f1 = int(input('enter a number between 1 and 10: '))

Or do it later inside of a try: except: block.

Sebastian Simon
  • 16,564
  • 7
  • 51
  • 69
Wasif
  • 13,656
  • 3
  • 11
  • 30