Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with elif?
#1
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')
Reply


Messages In This Thread
problem with elif? - by Osires - Sep-05-2017, 12:27 AM
RE: problem with elif? - by metulburr - Sep-05-2017, 01:03 AM
RE: problem with elif? - by Osires - Sep-06-2017, 01:42 AM
RE: problem with elif? - by ichabod801 - Sep-05-2017, 01:05 AM
RE: problem with elif? - by metulburr - Sep-07-2017, 06:42 PM
RE: problem with elif? - by Osires - Sep-09-2017, 06:33 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Functions and if elif problem Bruizeh 2 3,829 Aug-27-2021, 03:37 AM
Last Post: naughtyCat

Forum Jump:

User Panel Messages

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