summaryrefslogtreecommitdiff
path: root/comp/work/17/bedroom.py
blob: d164cf8a4b031a8816ed2cf10a84986a7a554a66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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}")