-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator-pos-terminal.py
73 lines (41 loc) · 1.75 KB
/
calculator-pos-terminal.py
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
### Point of Sale Terminal
### by Andrew Kramer
#
"""
This program is a simple POS terminal demo.
It asks the user for an item name, price, and quantity. It then presents the sub total for each respective item, and concludes with a grand running total.
"""
### PSEUDOCODE
"""
Define the main function:
- Allow for a total of 3 entries with a constant named MAX
- Establish a variable to work as a price accumulator.
- Ask the user for the item_name, unit_price, and quantity.
- For each item, calculate the sub_total with the formula:
sub_total = unit_price * quantity
- For each itea, print the formula result.
- After printing the result, ask for the next item.
- After printing the last (3) item, print the grand_total of all three items.
"""
def main():
# Establish the maximum amount of entries.
MAX = 3
# Initialize an accumulator variable.
grand_total = 0.0
# Establish accumulator.
for counter in range(MAX):
# Ask the user for the name of the item.
item_name = input('Enter item name ' )
# Ask the user for the price of the item.
unit_price = float(input(f'Enter unit price of {item_name} '))
# Ask the user for the quantity of the item.
quantity = int(input(f'Enter quantity of {item_name} '))
# Calculate the sub_total.
sub_total = unit_price * quantity
# Print the quantity, item name, and total for the current item.
print(f'{quantity} {item_name} @ ${unit_price:.2f}, total ${sub_total:.2f}')
# Add the accumulator variable into the for loop to accumulate the grand_total.
grand_total = grand_total + sub_total
# Print the grand total.
print(f'Total of these three items is ${grand_total:.2f}')
main()