'int'对象不可调用错误,而True Loop

时间:2015-11-15 17:48:32

标签: python-3.x

数学测验

import random
import math
import operator

def questions():
    # Gets the name of the user
    name= input("What is your name")
    for i in range(10):
    #Generates the questions
        number1 = random.randint(0,100)
        number2 = random.randint(1,10)
    #Creates a Dictionary with the symbols as the keys and the opertations as the values
        Operands ={'+':operator.add,
                   '-':operator.sub,
                   '*':operator.mul,
                   '/':operator.truediv}
        #Creast a list containing a tuple which contains the dictionary keys       
        Ops= random.choice(list(Operands.keys()))
        # Makes the  Answer variable availabe to the whole program for later use
        global answer
        # Gets the answer
        answer= Operands.get(Ops)(number1,number2) # Returns a value for the given key
        # Makes the  Sum variable  avialbe to the whole program for later use
        global Sum
        # Ask the user the question 
        Sum = ('What is {} {} {} {}?'.format(number1,Ops,number2,name))
        print (Sum)

异常处理

    while True:
        try:
            global UserAnswer  # Makes the UserAnswer varialbe availbe to the whole program for later use
            UserAnswer= float(input()) # Convertss the input into a floating number that can be operated
            break
        except ValueError:
            print(" Oops! That was not a valid number. Try again..." )

    return answer


def askQuestion():
    answer =questions()
    guess = UserAnswer
    return guess == answer






def score():
            score = 0
            for i in range(10):
                correct= questions()
                if UserAnswer == answer :
                    score =score + l1
                    print("You got it right \n ")
                else:
                    print("You got it wrong \n")

            print("You got {} out of 10 \n".format(score))     

    ok= True
    while ok== True:
        questions()
        score()
        WhichClass(name,score)

        ask=(input("Another ? "))

        if ask in ('y','yes','Y'):
            ok=True
        else:
            ok=False

我已经编写了一个快速生成的程序。如果需要,我已经添加了一个True循环来再次运行程序。但是,当我运行该程序时,我收到以下错误:

What is 93 - 3?
90
Traceback (most recent call last):
  File "/Users/Family/Google Drive/V4.4.py", line 114, in <module>
    score()
TypeError: 'int' object is not callable

导致我的错误的原因。

0 个答案:

没有答案
相关问题