Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random library
#4
Well, by calling random.Choice() on every line, the interpreter is selecting a different element each time. In essence, you have approximately a 3.5% chance of the code ever working. Instead, store the result of random.Choice() in a variable and then check that variable in your if...elif statement.

x = random.choice(insieme)
if x == 'forbice':
    print('Hai perso :(')
elif x == 'carta':
    print('Pareggio')
elif x == 'sasso':
    print('Hai vinto!!')
Reply


Messages In This Thread
random library - by FedeZsuper - Oct-26-2020, 06:14 PM
RE: random library - by Larz60+ - Oct-26-2020, 06:38 PM
RE: random library - by bowlofred - Oct-26-2020, 06:57 PM
RE: random library - by stullis - Oct-26-2020, 06:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,788 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020