30 lines
648 B
Python
30 lines
648 B
Python
from decimal import Decimal
|
|
#引入decimal模块是因为python不是默认高精浮点数
|
|
|
|
def main():
|
|
print('==Exercise 5==')
|
|
|
|
flag=True
|
|
while flag:
|
|
a = input("number1=")
|
|
try:
|
|
a = Decimal(a)
|
|
flag=False
|
|
except :
|
|
print("pls input a number!")
|
|
flag=True
|
|
while flag:
|
|
b = input("number2=")
|
|
try:
|
|
b = Decimal(b)
|
|
flag=False
|
|
except :
|
|
print("pls input a number!")
|
|
|
|
print(f"The result is {a+b if a*b>Decimal(1000.0) else a*b}")
|
|
|
|
print('==End Of Ex5==')
|
|
return 0
|
|
|
|
if __name__ == '__main__':
|
|
main() |