Added week 6
This commit is contained in:
30
week6/ex5.py
Normal file
30
week6/ex5.py
Normal file
@@ -0,0 +1,30 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user