Question

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?Grocery Items quantity price 1 $ total $ $ $ $ $ ՄԴ Item Apples Peanut Butter Cereal Campbells Soup Sweet Corn Barilla Pasta

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The codet to do so is as follows, it is well commented:

1 print({0:22} {1:10} {2:10} {3:10}.format(Item ,quantity, price, total)) 2 #Store all the three details in arrays

The output looks like:

quantity 1 $ 2 $ 1 $ 5 $ 8 $ 4 $ 1 $ 3 $ 1 $ 1 $ 2 $ price 5.92 $ 6.66 $ 3.64 $ 0.98 $ 0.98 $ 1.28 $ 9.98 $ 1.48 $ 1.53 $ 9.9

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))

Add a comment
Know the answer?
Add Answer to:
We are using GitLab and Python3 to recreate a Grocery List. Using only print statements, variables,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT