lundi 25 mars 2019

Conditional Statement Issue [duplicate]

This question already has an answer here:

I'm making a program to help elementary students classify animals, however, my conditional statements and logical statements aren't working as intended.

This is basically how I want it to work:

  • Choose 1 to identify or 2 to research a class
  • If 1, user will answer 5 questions (user defined functions) to narrow down the possibility of the class
  • If 2, user will select a class from those printed to screen and then is given a summary on the class (also functions)

This issue is regardless of what the user enters in the prompt (eg. "def question_1"), the program always executes the first "if" statement. So if I enter "n" (in def question_1), I would expect answer1 to contain "notWet", however, "isWet" is still assigned. Is my structure incorrect? This issue persists in both my choices 1 and 2.

I also wish to remove each answer from each function after it assigned, to append to the "animal" list at the top. Again I'm a beginner to programming so please excuse any sill mistakes. I'm using pycharm. All help appreciated.

Honestly, I've tried a lot of syntax stuff. Indentations, moving some code up or down etc. Nothing seems to work

animal = [ ]

#FUNCTIONS
def question_1():

print("Enter 'Y' for yes or 'N' for no")

answer1 = input(str("Does the animal live in water? "))

    if answer1 == "Y" or "y":

        answer1 = "isWet"

    elif answer1 == "N" or "n":

        answer1 = "notWet"

    return answer1


def fish():

    print("Fishes, sci-----


def bird():

    print("Birds----


# INTERFACE
choice = input(str("Enter 1 or 2: "))

  if choice == "1": 

 question_1()

elif choice == "2":

ani = input(str("Please select the animal class you wish to research. "))

print("\n")

if ani == "Fish" or "fish":

print(fish())

elif ani == "Bird" or "bird":

print(bird())

Aucun commentaire:

Enregistrer un commentaire