编程口算题输答案后判断对错,Python编程语句怎么写?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了编程口算题输答案后判断对错,Python编程语句怎么写?相关的知识,希望对你有一定的参考价值。

import random


flag = ["+","-","×","÷"]

a1 = random.randint(0,9)

a2 = random.randint(0,9)


i_flag = random.randint(0,3)


str = f"a1 flag[i_flag] a2 = "

result = None

if flag[i_flag] == "+":

   result = a1 + a2

elif flag[i_flag] == "-":

     result = a1 - a2

elif flag[i_flag] == "×":

    result = a1 * a2

elif flag[i_flag] == "÷":

    result = a1 / a2

else:

    pass


ins = input(str)


if f"result" == ins:

   print(f"ins is correct! ")

else:

   print(f"ins is wrong, right answer is : strresult")

参考技术A

import random


flag = ["+","-","×","÷"]

a1 = random.randint(0,9)

a2 = random.randint(0,9)


i_flag = random.randint(0,3)


str = f"a1 flag[i_flag] a2 = "

result = None

if flag[i_flag] == "+":

   result = a1 + a2

elif flag[i_flag] == "-":

     result = a1 - a2

elif flag[i_flag] == "×":

    result = a1 * a2

elif flag[i_flag] == "÷":

    result = a1 / a2

else:

    pass


ins = input(str)


if f"result" == ins:

   print(f"ins is correct! ")

else:

   print(f"ins is wrong, right answer is : strresult")

以上是关于编程口算题输答案后判断对错,Python编程语句怎么写?的主要内容,如果未能解决你的问题,请参考以下文章

青少年编程 电子学会python编程等级考试一级真题解析(判断题)2021-6

电子学会青少年软件编程 Python编程等级考试二级真题解析(判断题)2020年9月

电子学会青少年软件编程 Python编程等级考试一级真题解析(判断题)2021年12月

电子学会青少年软件编程 Python编程等级考试三级真题解析(判断题)2021年3月

电子学会青少年软件编程 Python编程等级考试三级真题解析(判断题)2021年3月

电子学会青少年软件编程 Python编程等级考试一级真题解析(判断题)2021年12月