L


私信TA

用户名:uq_26544849224

访问量:98

签 名:

等  级
排  名 25490
经  验 546
参赛次数 0
文章发表 4
年  龄 0
在职情况 学生
学  校 zzu
专  业

  自我简介:

TA的其他文章

import sys
def jud(x):
    m = 0
    for i in x:
        if i == '-' or i == '+':
            return m
        m+=1
def jud2(s):
    m = 0
    for i in s:
        if i == '=':
            return m
        m+=1
n = 0
a = 0
b = 0
c = 0
while True:
    try:
        line = input()
        if line[-1] == '?':
            continue
        else:
            a = int(line[0:jud(line)])
            b = int(line[jud(line) + 1:jud2(line)])
            c = int(line[jud2(line) + 1:])
            if line[jud(line)] == '+' and c == a + b:
                n += 1
            elif line[jud(line)] == '-' and c == a - b:
                n += 1
            else:
                continue
    except:
        break

print(n)

好的题解

#判断结果是否正确的函数
def check(s):
    if '?' in s:
        return False
    else:
        L = list(s)
        L.insert(L.index('='),'=')
        if eval("".join(L)):
            return True
        else:
            return False
#正确题目数量
count = 0
while True:
    try :
        S = input()
        if check(S):
            count += 1
    except:
        break
print(count)

好的题解2

score = 0
while True:
    try:
        user = input().split("=")
        if user[1] == "?":
            continue
        if str(eval(user[0])) == user[1]:
            score += 1
    except:
         break
print(score)


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区