Added week 6

This commit is contained in:
2026-04-13 09:45:45 +08:00
parent 923c041dd6
commit 9b90ac4340
7 changed files with 139 additions and 0 deletions

30
week6/ex5.py Normal file
View 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()