We are using GitLab and Python3 to recreate a Grocery List.
Using only print statements, variables, and arithmetic operations
how would I go about writing the code for such a project?
The codet to do so is as follows, it is well commented:
The output looks like:
If you observe the code, i have to use the format() method to indent the blocks.
if the code helped you please upvote it, for any doubts post a comment, I will surely help.
Code:
print('{0:22} {1:10} {2:10} {3:10}'.format("Item" ,"quantity", "price", "total"))
# Store all the three details in arrays so that
# we can directly loop over and print the statements
items = ['Apples', 'Peanut Butter', 'Cereal', 'Camplbells Soup',
'Sweet Corn',
'Barilla Pasta', 'Laundry Detergent', 'Pineapple Chunks', 'Canola
Oil',
'Coffee', 'Prego Sauce', 'Rigatoni', 'Quaker Oats', 'LED light
Bulbs']
quantity = [1,2,1,5,8,4,1,3,1,1,2,3,2,1]
price = [5.92, 6.66,3.64,0.98,0.98,1.28,9.98,1.48,
1.53,9.96,1.88,1.00,3.88,4.97]
# variable to store the subtotal
val = 0
for i in range(len(items)):
# add to subtotal at each step
val = val + quantity[i]*price[i]
print('{0:18} {1:10} ${2:10}
${3:10.2f}'.format(items[i],quantity[i],price[i],quantity[i]*price[i]))
print('\n{0:40} ${1:8.2f}'.format("Sub total" , val))
print('{0:40} ${1:8.2f}'.format("Tax(7.35%)" , 0.0735*val))
# the {a:b.cf} format represents a as the parameter number
# b as the size of the output field, c as the number of
# digits after the decimal place
print('\n{0:40} ${1:8.2f}'.format("Total" , val +
0.0735*val))
We are using GitLab and Python3 to recreate a Grocery List. Using only print statements, variables,...