diff options
author | standenboy <standenboy@StandenboyLAP.lan> | 2024-01-17 13:13:58 +0000 |
---|---|---|
committer | standenboy <standenboy@StandenboyLAP.lan> | 2024-01-17 13:13:58 +0000 |
commit | e8366ab41644102a8db2ac0740212de982eb043b (patch) | |
tree | fe4ae3dbd332e19cc29f4109e10dad0146612d51 /comp | |
parent | 5fbd145a080da6c02a15cd4f78fab940ce046b09 (diff) |
did some comp sci homework
Diffstat (limited to 'comp')
-rw-r--r-- | comp/hw/110/cityProgram.py | 37 | ||||
-rw-r--r-- | comp/hw/110/search.py | 12 | ||||
-rw-r--r-- | comp/work/17/bedroom.py | 39 | ||||
-rw-r--r-- | comp/work/17/price.txt | 3 |
4 files changed, 91 insertions, 0 deletions
diff --git a/comp/hw/110/cityProgram.py b/comp/hw/110/cityProgram.py new file mode 100644 index 0000000..9a92e53 --- /dev/null +++ b/comp/hw/110/cityProgram.py @@ -0,0 +1,37 @@ +Country = ["France", "UK", "Italy", "Spain"] +Capital = ["Paris", "London", "Rome", "Madrid"] + +def add(country, capital): + Country.append(country) + Capital.append(capital) + +def remove(country): + counter = 0 + for i in Country: + if i == country: + Country.pop(counter) + Capital.pop(counter) + break + counter = counter+1 + +def printCountry(): + counter = 0 + for i in Country: + print(Country[counter], Capital[counter] ) + counter = counter + 1 + +while True: + query = input("add, remove, print: ") + if query == "add": + add(input("country: "), input("capital: ")) + printCountry() + elif query == "remove": + remove(input("country to remove: ")) + printCountry() + elif query == "print": + printCountry() + + + + + diff --git a/comp/hw/110/search.py b/comp/hw/110/search.py new file mode 100644 index 0000000..99f8b3d --- /dev/null +++ b/comp/hw/110/search.py @@ -0,0 +1,12 @@ +names = ["jacob", "thor", "katelyn", "johnson"] + +searchingFor = input("name to look for: ") +for i in names: + if i == searchingFor: + print("found name") + exit(0) + +print("name not found") + + + 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}") diff --git a/comp/work/17/price.txt b/comp/work/17/price.txt new file mode 100644 index 0000000..a0e4a0e --- /dev/null +++ b/comp/work/17/price.txt @@ -0,0 +1,3 @@ +pens,13,1.80 +rubbers,8000,0.01 +rulers (beating kind),69420,100 |