Python Forum
Add food choice to menu
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add food choice to menu
#2
A few things:

1. Why do you redeclare menu each time in the loop? Surely you only need to declare it once outside?
2. You've been told this in another thread, but if you want several items, you don't need to put them in a single string; you can use a list, tuple or set instead. If you are going to use a string, you don't need the parens on line 4.
3. You have several problems with the tries variable:

- On line 2, you initialise it with an empty string. Why and not a 0? With the code as it is, you should be seeing an exception on line 7, because you can't add an int to a string.
- The variable is redeclared each time in the loop, so even if you had initialised it to 0, it would be reset to 0 each iteration, meaning that on every iteration it would be set to 1 on line 7 and so the expression tries == 4 would never be true. Again, surely you want to declare it before the loop with its initial value.

4. You really don't need line 3, since you're immediately overwriting the value of add_menu with the value you get from input on line 5.

5. Think about line 6 and the menu variable. Do you think that what you've written there is correct?
Reply


Messages In This Thread
Add food choice to menu - by extricate - Jun-07-2020, 05:39 AM
RE: Add food choice to menu - by ndc85430 - Jun-07-2020, 06:24 AM
RE: Add food choice to menu - by extricate - Jun-07-2020, 07:04 AM
RE: Add food choice to menu - by DPaul - Jun-13-2020, 07:24 AM
RE: Add food choice to menu - by Yoriz - Jun-13-2020, 07:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Building a food delivery program ElenaPapagia 2 5,050 Dec-12-2020, 04:12 PM
Last Post: michael1789

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020