我有2个问题。 我的第一个问题是我不知道如何编写整数代码。输出应该写为整数...但是当我使用例如4.3 + 5时它不起作用...答案应该是“简单地” 9 ... ValueError:以10为底的int()的无效文字: 有人可以帮我写这个小计算器吗?
operation = input('Select an operation (type "addition","subtraction","multiplication",or "division" and hit enter)')
datatype = input('Select a datatype (type "int" or "float" and hit
enter)')
value1 = input('Value 1:')
value2 = input('Value 2:')
result = None # This variable should be overwritten with the result of
your operation later.
if datatype == "float":
value1 = float(value1)
value2 = float(value2)
else:
value1 = int(value1)
value2 = int(value2)
if operation == "addition":
result = value1+value2
elif operation == "subtraction":
result = value1-value2
elif operation == "multiplication":
result = value1*value2
elif operation == "division":
result = value1/value2
print(f"Result: {result}")
这是输出中的其他问题->它总是向我显示整个计算...但是我只想要解决方案。
输出为:
Select an operation (type "addition",or "division" and hit enter)multiplication
Select a datatype (type "int" or "float" and hit enter)float
Value 1:123456789123456789123456789
Value 2:-4.3
123456789123456789123456789 * -4.3 =
Result: -5.3086419323086415e+26
输出应为:
Select an operation (type "addition",or "division" and hit enter)multiplication
Select a datatype (type "int" or "float" and hit enter)float
Value 1:123456789123456789123456789
Value 2:-4.3
Result: -5.3086419323086415e+26