Python调试。帮助一个菜鸟:(

时间:2013-05-26 03:01:38

标签: python windows macos debugging

我已经开始学习python,我需要一些帮助。什么都有帮助

我用:

komodo edit< - 编写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"    `

1 个答案:

答案 0 :(得分: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"