0

我已经开始学习python,我需要一些帮助。任何事情都会有帮助

我用:

科莫多编辑<-编写python

终端(我的编辑器)<-错误测试

def score():
    question_1 = "null" #var
    question_2 = "null" #var
    q_1_answer = 0 #var
    q_2_answer = 0 #var

while 1:
    try:
        question_1 = raw_input("do you like green eggs and ham? str((y/n))") # avoid malicious input
    except (y or n ): # but this input
        q_1_answer = 1 # do this
        break # stop the while loop


 while 1:

    try:
        question_2 = raw_input("do you like yellow eggs and spam? str((y/n))")
    except (y or n ):
        q_2_answer = 1
        break



  # I respond to input
if question_1 == y:
    print "green eggs str(0_o")\""

elif question_1 == n:
    print "yay 1"

else:
    print "error, you beat my code! Well done!"




   # I respond to input
if question_2 == y:
    print "yellow eggs str(0_o")\""

elif question_2 == n:
    print "yay 2"

else:
    print "error, you beat my code! not well done! shame!!!!!!!!"



    # answer total question: my input


if q_2_answer + q_1_answer > 2:

    return "oi you did well. thanks!!!!"

elif q_2_answer + q_1_answer > 1:
    return "you only answered one question?"

else
    print "not funny"    `
4

1 回答 1

0

这些代码现在可以运行没有错误,但您仍然需要完善逻辑。当心!!不要使用“空格键”来代替“制表符”。

while 1:
    try:
       question_2 = raw_input("do you like yellow eggs and spam? str((y/n))")
    except (y or n ):
        q_2_answer = 1
        break



  # I respond to input
if question_1 == y:
   print "green eggs str(0_o)"

elif question_1 == n:
   print "yay 1"

else:
   print "error, you beat my code! Well done!"




   # I respond to input
if question_2 == y:
    print "yellow eggs str(0_o)"

elif question_2 == n:
    print "yay 2"

else:
    print "error, you beat my code! not well done! shame!!!!!!!!"



    # answer total question: my input


if q_2_answer + q_1_answer > 2:
    print "oi you did well. thanks!!!!"

elif q_2_answer + q_1_answer > 1:
    print "you only answered one question?"

else:
    print "not funny"
于 2013-05-26T03:22:46.493 回答