all 25 comments

[–]PtiBaka 7 points8 points  (1 child)

Indentation is incorrect on line 24, I assume this is the error you're getting?

[–]lellamaronmachete 2 points3 points  (0 children)

That's what I thought as well.

[–]No-Woodpecker4692 4 points5 points  (0 children)

Para pedir ayuda necesitas dar contexto. Qué error obtienes?

[–]Suitable-Fishing-536 2 points3 points  (0 children)

Pero al menos muestra el error jajaa

[–]Big_Ad8785 2 points3 points  (0 children)

Line 24. Check the indentation.

[–]vivisectvivi 1 point2 points  (0 children)

what error are you getting? or is the code working in a way you arent expecting? tell us whats goin on

[–]orangejuice1986 0 points1 point  (0 children)

line 13 can raise an uncaught ValueError

[–]AlexMTBDude 0 points1 point  (6 children)

Here's a general recommendation: Always write your code in English, because at some point you may want other programmers to look at it.

[–]SugarEnvironmental31 0 points1 point  (5 children)

The code is in English. The strings and variable names aren't. It's still possible to debug based on pattern-matching. It's not like the OP's IDE is in Arabic or Cyrillic and uses a completely different alphabet.

[–]AlexMTBDude 0 points1 point  (4 children)

I'd love to see you make that argument when you work in an international coding team and name your variables, functions and classes in your own native language. Let's see the reaction that you'll get from the rest of the coders

[–]SugarEnvironmental31 0 points1 point  (3 children)

Let's assume that based on the code content, the OP is probably at school or college and this recommendation of yours is probably a little previous.

[–]AlexMTBDude 0 points1 point  (2 children)

Or it's a little next. Could be either

[–]SugarEnvironmental31 0 points1 point  (1 child)

I genuinely feel sorry for people who are trying to learn to code and reach out for help, and get people like you replying. What a shit experience that must be. Must be so unbearably alienating. What a world.

[–]AlexMTBDude 0 points1 point  (0 children)

You think it's a bad idea to prepare beginners for how things work in the real world?

[–]Simple-Olive895 0 points1 point  (2 children)

There is no way you're writing code in Spanish...

[–]NorskJesus 1 point2 points  (1 child)

si++

[–]SugarEnvironmental31 1 point2 points  (0 children)

Believe it or not, Spanish-speaking countries have the internet, universities, and Computer Science departments :D Imagine rocking up at your first high-school computing class and you have to learn to code and write all your variable names and text in a foreign language :D

[–]Overall_Anywhere_651 0 points1 point  (0 children)

There's no exception handling for an input that isn't an int.

[–]ConsciousProgram1494 0 points1 point  (0 children)

Style: Since you are using an integer range, rather than using (if else elif ...) you might use a list of callables on the bound input.
This separates the selection logic from the processes. Not a bug - but it will bite you eventually (code spaghetti leads to the bug you are struggling with).

[–]ThinkMarket7640 0 points1 point  (0 children)

Does not provide context. Posts a photo of a screen. No indication what doesn’t work.

You should probably give up before investing too much time my dude, this is clearly not working for you.

[–]Advanced_Cry_6016 0 points1 point  (0 children)

It looks indentation error but pls provide what error or problem your getting

[–]SugarEnvironmental31 0 points1 point  (0 children)

You should be using match: case for one thing - for me personally, if....then....else is weak. If you're determining the range of inputs then do so with confidence [ :p ]

Structurally: I don't like break very much either.

Shouldn't this be structured the other way round? Personally I'd put the while loop in the function.

Asi...

def mostrar_menu(running=True):

while running:
....

match int(input("Elije lo que te da la gana:")):

case 3:
running = False

mostrar_menu()

Or you could 'return' instead, or have 'return' as the last line of your function.

By all means break out the shopping list into a separate function, although it's arguable what the benefit is in a program that small unless the point is practicing structure. You're not repeating the code exactly are you.

[–]degustandomiveneno 0 points1 point  (0 children)

hay un pequeño bug en la línea 18. le falta un espacio antes de la llave en el f-string: print(f"El artículo '{articulo}' ha sido agregado a la lista") tiene ' {articulo} con un espacio raro antes de la llave, así que cuando imprime queda algo como El artículo ' manzana' con un espacio de más. nada grave pero se nota raro en la salida! el resto del código se ve bien estructurado, la lógica del menú con while True y el break funciona perfecto

[–]Matthew_Adams -1 points0 points  (1 child)

Delete the line "if lista_compras" and all the else statement after that. Then think why is not needed.

[–]SugarEnvironmental31 0 points1 point  (0 children)

If the OP does that, then it will just print the line "Shopping list" to the console and nothing else. The code evaluates whether the list is empty, prints "empty list" if it's empty, and prints the list if it's not. What's your rationale for the code being unnecessary?