school

thing1's amazing school repo
Log | Files | Refs | Submodules | README

bedroom.py (998B)


      1 def validquantity(num):
      2     try:
      3         num = int(num)
      4     except Exception as e:
      5         print("invalid input: NOT INT") 
      6         return False
      7     if num < 0:
      8         print("invalid input: NUMBER LESS THAN 0")
      9         return False
     10     return True
     11 
     12 def validprice(num):
     13     try:
     14         num = float(num)
     15     except Exception as e:
     16         print("invalid input: NOT INT") 
     17         return False
     18     if num < 0:
     19         print("invalid input: NUMBER LESS THAN 0")
     20         return False
     21     if (str(num)[::-1].find('.') > 2): 
     22         print("invalid input: NUMBES HAS TO MANY DECIMAL PLACES")
     23         return False
     24     return True
     25     
     26 
     27 f = open("price.txt", "r")
     28 for i in f.readlines():
     29     item = i.split(",")[0]
     30     quantity = i.split(",")[1]
     31     price = i.split(",")[2]
     32     
     33     if (validquantity(quantity) == False):
     34         exit(1)
     35     elif (validprice(price) == False):
     36         exit(1)
     37     quantity = int(quantity)
     38     price = float(price)
     39     print(f"{item} will cost {price*quantity:.02f}")