Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random library
#3
Please fix the opening tag. Should just be python in brackets. Click the python icon button to insert them automatically.

Each time you call random.choice(insieme), you're making a new choice. Often rather than rechoosing, you want to make one choice, remember it, then do your comparisons against that choice. Otherwise you might pick the second one on the first check (so it doesn't print), then on the second check it picks the first choice. You might never match any of them. By remembering the choice, you know you should match one of them.

Something like:
mychoice = random.choice(insieme)
if (mychoice) == 'forbice':
    print('Hai perso :(')
elif (mychoice) == 'carta':
    print('Pareggio')
elif (mychoice) == '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,843 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