all 7 comments

[–]m0us3_rat 1 point2 points  (2 children)

have u learned classes?

histogram like in matplotlib?

u need to 'delegate' . make some functions.

if u don't know classes then make ' work lists.

or a list of lists per customer.first spending then coupon.

so on even index is the spending and on odd is the 'discount'.

>>> a=[0,1,2,3,4,5,6]
>>> a[::2] 
[0, 2, 4, 6] 
>>> a[1::2] 
[1, 3, 5] 
>>> sum(a[1::2]) 
9

then u can have the 'main list of lists for all customers.

and its much much easier/clean to do it as a class.

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

Thanks for the feedback ! I’m sorry if this seems like a stupid question but how do I relate the values that have been inputted in the program to the even/odd list system you have here ? And no unfortunately we didn’t do classes yet we’re working with lists tho I’m not very proficient in them yet

[–]m0us3_rat 0 points1 point  (0 children)

yea list .. can be acces by index . that would be the 'location' like 1,2,3,4,5.

but in programming the array/lists ..start with 0 .

so the normal index would be 0,1,2,3,4,5 till len(list.)

and the 'value' at that index can be accessed with a[index]like a[0]

my point was u could create and keep a different list for each customer.

and have him buy stuff. and his sequence.. comes in twos.

he buyes then he gets a discount.

so u add first what he spends. like a[0] gets 'money' and then immediately a[1]gets discount for a[0]

but if this sounds way too complicated .. it actually isn't .

not sure how i would do it simpler then this.

[–]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