Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

'if' command is interfering with another line of code [duplicate]

$
0
0

Im creating a crafting code and introduced a 'store' system where you buy materials, I also made a code that reverts to the starting line of code if you don't put in something right, but for some reason I can't figure out, the store code is interfering with this and is running the itself when I type something invalid instead of the revert code

noiron = 5nowood = 5invensw = 0invenwh = 0invenda = 0coins = 10while True:    make = input("do you want to make a dagger, warhammer or sword? you can also check your inventory or go to the store")    if make == "sword":        print ("you have made a sword")        print ("you now have " + str(noiron-3) +" iron left")        print ("you now have " + str(nowood-2) +" wood left")        invensw = 1        nowood = noiron - 2        noiron = noiron - 3    elif make == "warhammer":        print ("you have made an warhammer")        print ("you now have " + str(noiron-2) +" iron left")        print ("you now have " + str(nowood-3) +" wood left")        invenwh =  1        nowood = nowood - 3        noiron = noiron - 2    elif make == "dagger":        print ("you have made an dagger")        print ("you now have " + str(noiron-1) +" iron left")        print ("you now have " + str(nowood-1) +" wood left")        invenda = 1        nowood = nowood - 1        noiron = noiron = 1    elif make == "inventory":        print("you have " + str(nowood) +" wood")        print("you have " + str(noiron) +" iron")        if invenda == 0 and invenwh == 0 and invensw == 0:            print("you have no weapons")        else:            print("you have " + str(invensw) +" sword(s)")            print("you have " + str(invenwh) +" warhammer(s)")            print("you have " + str(invenda) +" dagger(s)")    elif make == "store" or "shops" or "shop":        shopin = input("do you want to buy wood or iron?")        if shopin == "wood":            nowood = nowood + 5            coins = coins - 2            print("you have bought 5 wood, it cost 2 coins")        elif shopin == "iron":            noiron = noiron + 5            coins = coins - 4            print("you have bought 5 iron, it has cost 4 coins")    else:        print("that is not valid, try again")

Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>