+ 1

Whats wrong with this code?

It seems pretty straightforward but why does it print only You Have Nothing no matter what? https://code.sololearn.com/cEiu0uoy6crq/?ref=app

27th Dec 2018, 3:33 PM
Zinnur Hossain
Zinnur Hossain - avatar
8 odpowiedzi
0
Sword = 1 Shield = 2 Sandals = 3 inventory = [ 1, 2] if Sword in inventory: print("You have Sword") if Shield in inventory: print("You have Shield") if Sandals in inventory: print("You have Sandals") if Sword and Shield and Sandals in inventory: print("You have Sword, Shield and Sandals") if Sword and Shield in inventory: print("You have Sword and Shield") if Sword and Sandals in inventory: print("You have Sword and Sandals") if Shield and Sandals in inventory: print("You have Shield and Sandals") else: print("You have nothing") This should work
27th Dec 2018, 3:59 PM
CodeMStr
CodeMStr - avatar
+ 3
Zinnur Hossain Good luck 👍
27th Dec 2018, 4:02 PM
Nick
Nick - avatar
27th Dec 2018, 3:59 PM
Nick
Nick - avatar
+ 2
Yeah both of them work, thanks!!!
27th Dec 2018, 4:01 PM
Zinnur Hossain
Zinnur Hossain - avatar
+ 2
Niek Aukes Try your code with inventory [2, 3].
27th Dec 2018, 4:10 PM
Diego
Diego - avatar
+ 2
Diego Acero Thank you for mentioning this, I'll change the example.
27th Dec 2018, 4:11 PM
Nick
Nick - avatar
+ 1
Nick I wouldn’t recommend naming a variable like a built-in function (e.g. str) as it may cause some problems.
27th Dec 2018, 4:04 PM
Diego
Diego - avatar
0
1(assigned to Sword) doesn't occur in inventory, if you want this to work, create a dictionary or replace "Sword" etc. with 1, 2 or 3 (in inventory). Or replace values with strings
27th Dec 2018, 3:55 PM
CodeMStr
CodeMStr - avatar