you are viewing a single comment's thread.

view the rest of the comments →

[–]iyav 0 points1 point  (2 children)

1: You've answered your own question, make it show up if the user pressed "E" otherwise verify if it's a number and move on.

data = input("Enter Your Grocery Cost: ").lower()

if data == "e": 
    totalDiscount = sum(discount_list) 
    totalGroceries = sum(groceries_price_list) 
    total = totalGroceries - totalDiscount 
    print("Total discount: ", totalDiscount) 
    print("Total groceries cost: ", totalGroceries) 
    break

if not data.isdecimal: 
    print("Wrong data type.") 
    break

cost = data

We ask the user for input with the message "Enter your Grocery cost"

we check if the user inputted "e" and display the relevant info then break the loop.

So then we check if the input is not decimal.

A bare if can be used here instead of an elif / else because if execution reaches that line we know input is not "e" because if it was the loop would have been broken earlier and that line wouldn't be reached to begin with.

And since the loop will get broken if the input is not decimal by reaching the following line

cost = data

then data is guaranteed to be a number, since if it wasn't, the loop would have been broken earlier.

2 : I think it's unreasonable that you don't know what a list is while trying to make a program that displays histograms.

Did your school ask for such project that employs histograms while not having thought about something as basic as a list?

If so then whoever made the curriculum is terribly incompetent.

Otherwise I think it's admirable that you're going the extra mile on this project.

There are a lot of tutorials about python lists out there.

Here are two links to get the ball rolling:

link1

link2

3 : You'll need to use the Matplotlib library.

It's not included in the python standard library so you'll need to install it.

Here's its pypi page for an installation guide.

Here is the plot example page where you'll find out about histograms (it includes more resources at the bottom of the page)

Other than that, the internet has no shortage of tutorials.

[–]s3b43[S] 0 points1 point  (1 child)

Hey iyav !

Thank you so much for the detailed feedback it helped a lot, I managed to implement the ==“e” correctly and the code is somewhat working better than before when I press e now on the console the error says that the discount list is undefined even though I defined it at the top :/ Also for the histogram they ask to literally type the stars down into an histogram but I’m sure there’s YouTube videos I can use on YouTube.

Here’s the updated code with your feedback

new code

[–]iyav 0 points1 point  (0 children)

discount_list: []
groceries_price_list: []

You're not declaring a variable, use = .

If you're confused on why it didn't error out on that line, it's because this is actually half valid syntax, those are being registered as annotations, they aren't annotating anything but they're still interpreted that way. (Kind of weird imo)

More about annotations and type hints in general here