Home  >  Article  >  Backend Development  >  python 简易计算器程序,代码就几行

python 简易计算器程序,代码就几行

WBOY
WBOYOriginal
2016-06-06 11:26:523182browse

代码:

代码如下:


import os
while True:
dynamic = input('输入计算表达式:')
if dynamic != 'cls':
try:
result = eval(dynamic)
print('计算结果:'+str(result))
except:
print('计算表达式输入有误!')
else:
command = 'cls'
os.system(command)

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn