lundi 25 novembre 2019

Python Code is currently choosing the appropriate "if/elif," but it also executes the else as well

I'm not sure if I am describing this correctly, but when my code goes through this if-else, when I input something, it will output the correct thing, (i.e. when I type in "age_up", the character age will increase by one. However, it will ALSO print out, "that is not a valid response." I am not sure what is wrong here, could someone give me some recommendations? Thanks!

Note: I imported random and time earlier in the code.

while True: #allows to make player keep entering input
    if imput in age_up and job == 0: #ages character up 1 year
        print(age + 1)
        age = age + 1
        time.sleep(1)
    elif imput in age_up and mafia_job == 1:
        age = age + 1
        print(age)
        time.sleep(1)
        money = money + 45600
        print("You now have " + money + "dollars in you bank account.")
        time.sleep(1)  
    elif imput in want_sad: #prints dumb stuff
        print(random.choice(sad))
        time.sleep(1.5)
    elif imput in spook_me: #prints dumb stuff
        print(random.choice(spoops))
        time.sleep(1.5)
    elif imput in vino: #prints vine references
        print(random.choice(vines))
        time.sleep(1.5)
    elif imput in no_job: #quits character's job
        job = 0
        mafia_job = 0
        doctor_job = 0
        vet_job = 0
        police_job = 0
        military_job = 0
        print("You quit your job.")
        time.sleep(2)
    elif imput in neckrope: #end the game early via suicide
        life_status = 1
        print("YOU ARE DEAD")
        exit()
    elif imput in police_job and job == 0 and secondary_diploma == 1: #allows you to apply to job if you do not already have a job and you graduated from secondary school
        job = 1
        police_career = 1
        print("You are now a police officer.")
        time.sleep(1)
    elif imput in police_job and job == 1: #tells character they cannot get this job because they already have a job
        print("You already have a job, and you do not have time to work two jobs.")
        time.sleep(1)
    elif imput in doctor_job and job == 0 and age == 18 and medical == 1:
        job == 1
        doctor_career = 1
        print("You are now a doctor.")
        time.sleep(1)
    elif imput in doctor_job and job == 1:
        print("You already have a job, and you do not have time to work two jobs.")
    elif imput in mafia_job and job == 0 and age > 14:
        job == 1 #makes it recognize that NOW you have a job
        mafia_career == 1
        print("Congrats. You joined the mafia.")
        time.sleep(1)
    elif imput in mafia_job and job == 0 and age < 14:
        print("Sorry, but you are too young to join the mafia.")
        time.sleep(1)
    elif imput in no_school and age >= 12:
        secondary_diploma = 0 #assumes you will not get a diploma
        school = 0 #says you are not in school
        print("You dropped out of school. Have fun with that!")
        time.sleep(1)
    elif imput in no_school and age < 12:
        print("You are not old enough to drop out of school.")
        time.sleep(1)
    elif imput in military_boi and age >= 17 and athletic_ability >= 8:
        job = 1
        military_career = 1
        print("You are now in the military.")
    elif imput in military_boi and age >= 17 and athletic_ability < 8:
        print("You are not fit for the military.")
        print("Try getting a different job, or going to the gym.")
        time.sleep(1)
    elif imput in military_boi and age < 17:
        print("You are not old enough to join the military.")
    elif imput in military_boi and job == 1:
        print("You already have a job. If you want to join the military, quit your job and try again.")
    elif imput in study:
        char_logic + .25
        print("Your logic is now " + char_logic)
        time.sleep(1)
    else:
        print("That is not a valid response. Please try again.")
        time.sleep(1)

Aucun commentaire:

Enregistrer un commentaire