Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi, im having a problem with a code. so far, here's what i got.

Python
import random
p = 0
mace = random.randint(5,9)
katana = random.randint(12,20)
club = random.randint(8,15)

bandage = random.randint(15,25)
medkit = random.randint(30,55)
painkillers = random.randint(7,16)

player_health = 100
equip = mace
items = {bandage,medkit}

zombie = 100

print '\nSo, Which way shall you go?'
direction = raw_input('Left or Right: ')

#player is in either location 1 or 2

if direction == 'Left' or 'left':
    p = p + 1
    print p
else:
    p = p + 2
    print p


it doesnt seem to return the value 2 when i input the word Right. am i forgetting something? thanks for the help :D

What I have tried:

if and elif, else and doble ifs.
Posted
Updated 12-Mar-18 18:41pm
v2
Comments
PIEBALDconsult 12-Mar-18 23:48pm    
Uh, yeah, it wouldn't. I suspect your if/or is wrong in a particular way.

1 solution

try
Python
if direction == 'Left' or direction == 'left':

the or operator work as: expression 1 or expression 2
Another way is to convert direction to uppercase before testing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900