Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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中的函数_Python_Python 3.x - Fatal编程技术网

与“有关”的错误==&引用;Python中的函数

与“有关”的错误==&引用;Python中的函数,python,python-3.x,Python,Python 3.x,我目前正在尝试用Python编写一个程序,它基本上会问你一些数学问题。由于某些原因,有很多错误,我不知道为什么,比如“!==”函数,它似乎不正确。可能还有其他一些问题,因为我刚刚开始使用Python。有人能告诉我如何使用!==功能正确,还有我的另一个问题:将“加法、减法或乘法”输入变成可能的命令? #随机输入 导入时间 选择=0 右侧=0 反错误=0 def add_question_to_file(a, b): with open("wrong_answers.txt&quo

我目前正在尝试用Python编写一个程序,它基本上会问你一些数学问题。由于某些原因,有很多错误,我不知道为什么,比如“!==”函数,它似乎不正确。可能还有其他一些问题,因为我刚刚开始使用Python。有人能告诉我如何使用!==功能正确,还有我的另一个问题:将“加法、减法或乘法”输入变成可能的命令? #随机输入 导入时间 选择=0 右侧=0 反错误=0

def add_question_to_file(a, b):
    with open("wrong_answers.txt", 'a') as f:
      f.write(f"{a} {operation} {b}\n")

def test(a,operation,b):
    user_input = int(input(f"{a} {operation} {b} = "))
    if user_input == a + b:
        print("You got it right!")
        counterright += 1 
    while user_input != a + b:
        if user_input == a + b:
            print("You got it right!")
            counterwrong += 1
            break
        else:
            add_question_to_file(a, b)
            print("Try Again!")
            user_input = int(input(f"{a} + {b} = "))

def get_question():
    a = random.randint(1, 10)
    b = random.randint(1, 10)
    with open("calc_log.txt", 'a') as f:
      if a<b: #insures a is always greater than b
        a, b = b, a
      f.write(f"{a} {operation} {b}\n")

def check_operation():
      if operation !==t "+" or "-" or "*"
        print("Sorry, that's invalid. You have to choose of the three operations!")

t1=time.perf_counter()  #

m = input("What mode would you like to use? Review/Normal. Choose Normal if this is your first time!")
operat ion = input("Which operation would you like to use? +,-,or *?")

if m == "review":
    with open("wrong_answers.txt", 'r') as f:
        for line in f:
            a, operation, b = line.split()
            test(int(a), int(b))
elif m == "normal":
    num_questions = int(input("How many questions would you like to do? "))
    for i in range(num_questions):
        print(f"You are on question {i + 1}: ")
        get_question()  

t2=time.perf_counter() #

print("It took you", t2-t1, "seconds for you to solve this problemset") #

print ("You got",counterright,"correct and",counterwrong,"wrong.")
def将问题添加到文件(a,b):
将open(“error_answers.txt”,“a”)作为f:
f、 写入(f“{a}{operation}{b}\n”)
def测试(a、操作、b):
user_input=int(输入(f{a}{operation}{b}=“))
如果用户输入=a+b:
打印(“你做对了!”)
右上角+=1
当用户输入时!=a+b:
如果用户输入=a+b:
打印(“你做对了!”)
反错误+=1
打破
其他:
将问题添加到文件(a,b)
打印(“重试!”)
user_input=int(输入(f“{a}+{b}=”)
def get_question():
a=random.randint(1,10)
b=随机随机随机数(1,10)
将open(“calc_log.txt”,“a”)作为f:

如果a则python中的不相等函数为!=。双等号(=)仅在要检查是否相等时使用。我希望这有帮助

原因!==不起作用是因为这不是python中的运算符。尝试使用!=。它的意思是不相等。

!=而不是==没有
==函数。有一个
=运算符,我猜这就是你的意思。唯一具有
的语言==是javascript。@juanpa.arrivillaga。