mardi 19 avril 2016

Python If Statement Not Functioning Properly [duplicate]

This question already has an answer here:

Here is the following code for a program I'm making to troubleshoot for a broken mobile phone, and the last If statement prints 'Test' no matter what the input is, I'm not 100% sure as to why its not working and that's why I need help (Don't tag as duplicate please!)

    question_number = 1
    with open("questionsfile.txt", mode="r", encoding="utf-8") as myFile: 
        questionslist = myFile.read().splitlines() 
    while True: 
        user_name=input("Welcome! What is your name: ").lower() 
    if user_name.isalpha(): 
            break
        print ("Hold on.. That isn't a possible name? Try again...")
    print ("Hello",user_name .title(),", I'm here to help you to       troubleshoot your broken mobile phone!")
    while True:
             try: 
                 phone_make = int(input("\n What make of phone do you have,   please input the corresponding number: \n 1) IPhone \n 2) Samsung \n 3) Nokia \n 4) HTC \n 5) Motorola \n 6) Other \n Your corresponding number: ")) # This asks the user what type of phone they have, and gives them a list of possible options and they have to input the corresponding number for the phone make they have.
                 break
             except ValueError:
                print ("Wait a minute... That was not a valid number!  Try again...")
    if question_number == 1: 
        q1_answer = input(questionslist[0]) 
        if q1_answer == 'Y' or 'y': 
            print("Test") 
        elif q1_answer == 'N': 
            print("Test incorrect") 

Aucun commentaire:

Enregistrer un commentaire