Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的代码没有被破坏,为什么我的数学';这不管用。我正在使用python 3.2_Python - Fatal编程技术网

为什么我的代码没有被破坏,为什么我的数学';这不管用。我正在使用python 3.2

为什么我的代码没有被破坏,为什么我的数学';这不管用。我正在使用python 3.2,python,Python,我也做了菜单。主要问题在于while选择: import random points=0 score=0 math_score=0 correctage= False print ('Please choose one of the following: \n 1.General Quiz \n 2.Maths quiz \n 3.Exit/Quit') selection= input ('Choose what you want to do: ') while selec

我也做了菜单。主要问题在于while选择:

import random
points=0
score=0
math_score=0
correctage= False


print ('Please choose one of the following: \n 1.General Quiz \n 2.Maths        quiz \n 3.Exit/Quit')
selection= input ('Choose  what you want to do: ')
while selection:
menu = {}
menu['1']="General Quiz." 
menu['2']="Maths Quiz."
menu['3']="Exit"


while not correctage:
    if selection == '1':

        print ('Hello I am a Super Computer Genius Ajin')

        name= (input ( ' What is your Name?')).title()
        print( ' So your name is '  + name)
        try:

            age= int(input( ' How old are you?'))
            print( ' So your Age is '  +str( age))



            if age==14 or age==15:
                print('You can Enter')
                points=points+10
                print( name+ ', You got ' +str (points) + ' points')


                q1=input('Who won the last world cup ').upper()

                if q1=='GERMANY':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')



                q2=input('Who won the founder of apple ').upper()

                if q2=='STEVE JOBS':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')



                q3=input('Which company jailbroke ios 9 ').upper()

                if q3=='PANGU':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')



                q4=input('What is the name of the latest apple phone? ').upper()

                if q4=='IPHONE 6S':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')


                q5=input('What is he capital of India? ').upper()

                if q5=='NEW DELHI':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')







                q6=input('Who is the fastest man ? ').upper()

                if q6=='USAIN BOLT'or q6=='MO FARAH':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')





                q7=input('What is Android? ').upper()

                if q7=='OPERATING SYSTEM':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')


                q8=input('Who is Thomas Edison ? ').upper()

                if q8=='INVENTOR OF THE LIGHT BULB' or q8=='INVENTOR OF LIGHT BULB':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')



                q9=input('What does WWW mean ? ').upper()

                if q9=='WORLD WIDE WEB':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')


                q10=input('Latest windows operating system? ').upper()

                if q10=='WINDOWS 10':
                    print('Well Done')
                    points=points+1
                    score=score+1
                    print( name+ ', You got ' +str (points) + ' points')

                else:
                    print ('wrong')
                    points=points-0
                    print( name+ ', You got ' +str (points) + ' points')



                print(" Thank you for playing ", name, "You have scored" , score, 'out of 10')


                text_file= open ("general_quiz.txt", "a")

                text_file.write (name )
                text_file.write (" scored ")
                text_file.write(str(score ))
                text_file.write (' out of 10, ' )
                text_file.close()
                print ("previous people who have played and what they scored out of 10")
                text_file = open("general_quiz.txt", "r")
                print (text_file.read())
                text_file.close()
                break



            else:
                print (' you shall not pass')
                correctage=False
                break
        except:
            print('Not a Valid age')
            break





    elif selection =='2':

        for i in range(10):
            num1=random.randint(1,12)
            num2=random.randint(1,12)
            ops= ('+', '-', '*')
            operation= random.choice(ops)
            answer=1

            if operation == '+':
                answer == num1+num2
            elif operation == '-':
                answer == num1-num2
            elif operation == '*':
                answer == num1*num2

            maths_name= (input ( ' What is your Name?')).title()
            print( ' Hello '  + maths_name)

            print ('What is ' + str(num1) + operation + str(num2))
            user_answer= int(input('Enter answer: '))

            if user_answer == answer:
                print('correct')
                math_score=math_score+1
            else:
                print ('Incorect')
                math_score=math_score-0




            print(" Thank you for playing ", maths_name, "You have scored" , math_score, 'out of 10')
            text_file= open("maths_score.txt", "a")

            text_file.write(maths_name )
            text_file.write(' Scored ')
            text_file.write (str(math_score ))
            text_file.write(' Out of 10, ')
            text_file.close()

            print('Previous people who have played are:')
            text_file= open("maths_score.txt", "r")
            print(text_file.read())
            text_file.close()



    elif selection =='3':
        break
    else:
        break
我的代码的问题是,数学测验不能正常进行,一般测验也不能中断,所以请有人来帮助我

我花了一天时间试图解决这个问题,错误在这里:

        if operation == '+':
            answer == num1+num2
        elif operation == '-':
            answer == num1-num2
        elif operation == '*':
            answer == num1*num2
表单
answer==num1+num2
的三行比较
answer
(您最初设置为
1
)是否等于
num1+num2
,然后对比较结果不做任何处理

我想你想要的是以下内容:

        if operation == '+':
            answer = num1+num2
        elif operation == '-':
            answer = num1-num2
        elif operation == '*':
            answer = num1*num2

您可能还想考虑将程序的一部分移动到<<代码>之外的<>代码>循环——此时,它在每个问题之前询问您的姓名。