题解 | #表达式求值#

表达式求值

https://www.nowcoder.com/practice/9566499a2e1546c0a257e885dfdbf30d

string = input()
safe_lst = ['+', '-','*','/','(',')','0','1','2','3','4','5','6','7','8','9']
test = False
for char in string:
    if char in safe_lst:
        test = True
    else:
        test = False
        break

if test == True:
    print(eval(string))
if test != True:
    print('unsafe input')

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务