Sep-05-2017, 12:27 AM
Okay, so this is a snippet of my code (the very beginning of it) that I have isolated in a separate file because it is dysfunctional. We are supposed to create a zombie survival game, but in this code here whenever you input anything other than "spas", it loops back to start (aka "Choose weapon: "). I've been fighting with this for a long time and now I've given up. I don't know what to do. I'm new to Python so please forgive the mess, I just need to know why my elif is just completely disregarded. I'm using Python 2.7.13
crowbar = 'crowbar' and 'Crowbar' and 'crow bar' and 'Crow bar' and 'Crow Bar' and 'bar' and 'Bar' spas = "Spas 12" and "spas 12" and "spas12" and "Spas" and "Spas12" and "spas" glock = "glock" and "glock 17" and "glock17" and "Glock" and "Glock 17" and "Glock17" for turn in range(100): weapon = raw_input("Choose weapon: ") if weapon == spas: weapon == "Spas 12" print ('You chose the Spas 12.') print ("\n-----------------------------------------------------------\n") for turn in range(100): name = raw_input("\nNow, what is your name? ") if (not name.strip()): print ("\nPlease enter your name.") name = raw_input("\nNow, what is your name? ") if (name.strip()): yesno = raw_input("\nOh, so your name is %s? Type \'yes\' or \'no\'. " % name.title()) if yesno in ["yes", "Yes", "y", "Y"]: print ("") print ("\n-----------------------------------------------------------\n") break elif yesno in ["No", "no", "n", "N"]: print ("\nHmm, that\'s not your name?") else: print ("\nPlease enter your name and confirm it with yes or no.") else: print ("\nHmm, that\'s not your name?") print ("You turn around. To your left is a gun shop, and to your right is a hospital. Keep in mind you just got into a car crash, but you never know what could be out there. Choose wisely, %s." % name.title()) break elif weapon == glock: weapon == "Glock 17" print ("You chose the Glock 17") print ("\n-----------------------------------------------------------\n") for turn in range(100): name = raw_input("\nNow, what is your name? ") if (not name.strip()): print ("\nPlease enter your name.") name = raw_input("\nNow, what is your name? ") if (name.strip()): yesno = raw_input("\nOh, so your name is %s? Type \'yes\' or \'no\'. " % name.title()) if yesno in ["yes", "Yes", "y", "Y"]: print ("") print ("\n-----------------------------------------------------------\n") break elif yesno in ["No", "no", "n", "N"]: print ("\nHmm, that\'s not your name?") else: print ("\nPlease enter your name and confirm it with yes or no.") else: print ("\nHmm, that\'s not your name?") print ("You turn around and to your left is a gun shop and to your right is a hospital. Keep in mind you just got into a car crash, but you never know what could be out there. Choose wisely.") break elif weapon == crowbar: weapon == "crowbar" print ("You chose the crowbar.") print ("\n-----------------------------------------------------------\n") for turn in range(100): name = raw_input("\nNow, what is your name? ") if (not name.strip()): print ("\nPlease enter your name.") name = raw_input("\nNow, what is your name? ") if (name.strip()): yesno = raw_input("\nOh, so your name is %s? Type \'yes\' or \'no\'. " % name.title()) if yesno in ["yes", "Yes", "y", "Y"]: print ("") print ("\n-----------------------------------------------------------\n") break elif yesno in ["No", "no", "n", "N"]: print ("\nHmm, that\'s not your name?") else: print ("\nPlease enter your name and confirm it with yes or no.") else: print ("\nHmm, that\'s not your name?") print ("You turn around and to your left is a gun shop and to your right is a hospital. Keep in mind you just got into a car crash, but you never know what could be out there. Choose wisely.") break else: print ('Error')