Python Forum
Can someone please help me with my code? (sorry to ask for so much help)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone please help me with my code? (sorry to ask for so much help)
#2
You need to assign the result of random.choice, and then test that. Something like:

elif player_choice == '3':
    attempt = random.choice(dodge1)
    if attempt == 1:
        print('You dodged the monsters attack!')
    ...
There's a little trick for random true/false: random.randrange(2) returns 0 or 1 randomly. 0 evaluates to False in a conditional, and 1 evaluates as true. So you can do this:

elif player_choice == '3':
    dodged = random.randrange(2)
    if dodged:
        print("You dodged the monster's attack!")
    ...
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Can someone please help me with my code? (sorry to ask for so much help) - by ichabod801 - Dec-06-2019, 09:51 PM

Forum Jump:

User Panel Messages

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