Commit 4242500a by likorn

python code is added

parent ce28b0b4
Showing with 47 additions and 0 deletions
def input_number(text):
n = input(text)
try:
float(n)
except ValueError:
return input_number("The value you've just entered is the wrong type. Try again!\n")
return float(n)
def read_array(n):
tv = []
for counter in range(n):
manufacture = input("The manufacture is ")
price = input_number("And the price is ")
tv.append({'manufacture': manufacture, 'price': price})
return tv
def read_discount(text):
d = input_number(text)
if d < 10 or d > 60:
return read_discount("The discount can't be less than 10 or greater than 60. Try another\n")
return d
def set_discount(tv, d):
for counter in range(0, len(tv)):
current = tv[counter]
new_price = current['price'] * (1.0 - (d / 100.0))
print("d: ", d, "old price: ", current['price'])
tv[counter]['new_price'] = new_price
return tv
def display(tv):
print('%-16s%-12s%-12s' % ("Manufacture", "Price", "New price"))
for each in tv:
print('%-16s%-12f%-12f' % (each['manufacture'], each['price'], each['new_price']))
number = int(input_number("Hey, how many TV sets do you want to compare?\n"))
tv_sets = read_array(number)
print(tv_sets)
discount = read_discount("Which discount do you want to get (in percents)?\n")
tv_sets = set_discount(tv_sets, discount)
display(tv_sets)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment