其他声明不起作用

时间:2016-11-12 18:59:03

标签: python

enter code here我刚学习python,最近我做了第一个测验项目。通过查看我的代码,您可以看到我有一些名为q1,q2等的变量,这些变量都在开头的主if语句下。由于某种原因,当你得到错误的答案时,第一个'else'语句会返回打印文本'nope',但在第一个问题之后,即使你得到了错误的答案,它也只打印'正确'。我希望有人能帮帮忙。感谢。

print ("Hello. Welcome to the quiz. You will have 10 minutes to complete the quiz and will be graded as you take it. Good Luck!")
begin = raw_input("Would you like to begin?: ")
if begin == "yes" or "Yes":
    print("Great! Lets get started")
    print ("A) The raw_input function waits for the user to type some input and press return. It then gets whatever was typed.")
    print ("B) It is a way to adjust the last variable written.")
    print ("C) It is the same as the 'input' function.")
    print ("D) It is not something that is built into python")
    q1 = raw_input("What is a raw input and what does it do?: ")
    if q1 == "A" or q1 == "a" :
        print ("Correct!")
        print("")
    else:
        print("nope")
    print("")

    print ("A) Any number that is a fraction.")
    print ("B) Any whole number that has a deceimal point.")
    print ("C) A data type that is a whole number and not a float.")
    print ("D) Any irational number.")
    q2 = raw_input("What is an integer?: ")
    if q2 == "C" or "c" :
        print ("Correct!")
        print("")
    else:
        print("nope")
    print("")

    print ("A) Any character or set of characters within single or double quotes.")
    print ("B) Any character or set of characters outside of quotes.")
    print ("C) A condition that can be changed depending on conditions passed through the program")
    print ("D) A set of whole numbers that are not fractions or floats.")

    q3 = raw_input("what is a string?")
    if q3 == "a" or "A" :
        print("Correct!")
        print("")
    else:
        print("Sorry that is not correct.")
    print("")

    print ("A) a,b,c,d,e ")
    print ("B) This will give you a syntax error")
    print ("C) It will print 'x'")
    print ("D) Nothing")
    q4 = raw_input("What will print, given the following code: x = [a,b,c,d,e], print x?: ")
    if q4 == "a" or "A" :
        print ("Correct!")
    else:
        print("Sorry the answer is 'A'")
    print("")

    print ("A) Loops allow us to execute a statement or group of statements multiple times.")
    print ("B) A group of lists set as a variable.")
    print ("C) A sequence of immutable Python objects.")
    print ("D) A data structure that includes 'if, else' statements.")
    q5 = raw_input("Which gives the best definition of a loop?")
    print("")
    if q5 == "a" or "A":
        print("Correct!")
    else:
        print("nope. The asnwer is A")

0 个答案:

没有答案