From e8366ab41644102a8db2ac0740212de982eb043b Mon Sep 17 00:00:00 2001 From: standenboy Date: Wed, 17 Jan 2024 13:13:58 +0000 Subject: did some comp sci homework --- comp/work/17/bedroom.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 comp/work/17/bedroom.py (limited to 'comp/work/17/bedroom.py') diff --git a/comp/work/17/bedroom.py b/comp/work/17/bedroom.py new file mode 100644 index 0000000..d164cf8 --- /dev/null +++ b/comp/work/17/bedroom.py @@ -0,0 +1,39 @@ +def validquantity(num): + try: + num = int(num) + except Exception as e: + print("invalid input: NOT INT") + return False + if num < 0: + print("invalid input: NUMBER LESS THAN 0") + return False + return True + +def validprice(num): + try: + num = float(num) + except Exception as e: + print("invalid input: NOT INT") + return False + if num < 0: + print("invalid input: NUMBER LESS THAN 0") + return False + if (str(num)[::-1].find('.') > 2): + print("invalid input: NUMBES HAS TO MANY DECIMAL PLACES") + return False + return True + + +f = open("price.txt", "r") +for i in f.readlines(): + item = i.split(",")[0] + quantity = i.split(",")[1] + price = i.split(",")[2] + + if (validquantity(quantity) == False): + exit(1) + elif (validprice(price) == False): + exit(1) + quantity = int(quantity) + price = float(price) + print(f"{item} will cost {price*quantity:.02f}") -- cgit v1.2.3