Restaurant at the End of the Universe

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
4
down vote

favorite












I wrote a basic menu application for my intro to python. I'm fairly new, and python does look promising. However, I am disappointed that it won't let me use Unicode.



the_burger = 16.99;
french_fries = 5.99;
currie_sauce = 19.99;
napkins_with_chocolates = 10.50;
juice_box = 89.01;
takeout = 18.99;
total = 0.0;
DONE = False
print("""
+-------------------------------------------+
| The Restaurant at the End of the Universe |
+---------------------------------+---------+
| AtThe "Big Boy" Burger | $""" + str(the_burger) + """ |
+---------------------------------+---------+
| BtFrench Fries | $""" + str(french_fries) + """ |
+---------------------------------+---------+
| CtCurrie sauce | $""" + str(currie_sauce) + """ |
+---------------------------------+---------+
| DtNapkins with Chocolates | $""" + str(napkins_with_chocolates) + str(0) + """ |
+---------------------------------+---------+
| EtJuice Box | $""" + str(juice_box) + """ |
+---------------------------------+---------+
| FtTakeout | $""" + str(takeout) + """ |
+---------------------------------+---------+
""");
while(not DONE):
print("Total:", total);
Item = input("Select a letter or 'done': ");
if Item is "A":
total += the_burger;
elif Item is "B":
total += french_fries;
elif Item is "C":
total += currie_sauce;
elif Item is "D":
total += napkins_with_chocolates;
elif Item is "E":
total += juice_box;
elif Item is "F":
total += takeout;
elif Item is "done":
print("Final total:", total);
DONE = True


The following is NOT intended for review, and is proof that it won't let me use unicode in python 3.6.5:



>>> print("♝ ♞ ♜ ")
Traceback (most recent call last):
File "jdoodle.py", line 1, in <module>
print("u265d u265e u265c ")
UnicodeEncodeError: 'ascii' codec can't encode character 'u265d' in position 0: ordinal not in range(128)
Command exited with non-zero status 1









share|improve this question



















  • 4




    It will let you use Unicode - and probably much more of Unicode than you're already using...
    – Toby Speight
    4 hours ago






  • 3




    Did you ask nicely? (What I mean is, how did you try? And how did it refuse? I know this isn't Stack Overflow, so the non-working code wouldn't be on-topic, but I'd be interested to know).
    – Toby Speight
    4 hours ago






  • 2




    Unicode is supposed to be available out-of-the-box. Example here.
    – Mathias Ettinger
    3 hours ago






  • 2




    Time to use a better IDE then: ideone.com/uK6XJ6
    – Mathias Ettinger
    2 hours ago






  • 2




    I'm not quite sure what the downvote is for... I've followed all of the rules for CR that I can tell.
    – FreezePhoenix
    1 hour ago














up vote
4
down vote

favorite












I wrote a basic menu application for my intro to python. I'm fairly new, and python does look promising. However, I am disappointed that it won't let me use Unicode.



the_burger = 16.99;
french_fries = 5.99;
currie_sauce = 19.99;
napkins_with_chocolates = 10.50;
juice_box = 89.01;
takeout = 18.99;
total = 0.0;
DONE = False
print("""
+-------------------------------------------+
| The Restaurant at the End of the Universe |
+---------------------------------+---------+
| AtThe "Big Boy" Burger | $""" + str(the_burger) + """ |
+---------------------------------+---------+
| BtFrench Fries | $""" + str(french_fries) + """ |
+---------------------------------+---------+
| CtCurrie sauce | $""" + str(currie_sauce) + """ |
+---------------------------------+---------+
| DtNapkins with Chocolates | $""" + str(napkins_with_chocolates) + str(0) + """ |
+---------------------------------+---------+
| EtJuice Box | $""" + str(juice_box) + """ |
+---------------------------------+---------+
| FtTakeout | $""" + str(takeout) + """ |
+---------------------------------+---------+
""");
while(not DONE):
print("Total:", total);
Item = input("Select a letter or 'done': ");
if Item is "A":
total += the_burger;
elif Item is "B":
total += french_fries;
elif Item is "C":
total += currie_sauce;
elif Item is "D":
total += napkins_with_chocolates;
elif Item is "E":
total += juice_box;
elif Item is "F":
total += takeout;
elif Item is "done":
print("Final total:", total);
DONE = True


The following is NOT intended for review, and is proof that it won't let me use unicode in python 3.6.5:



>>> print("♝ ♞ ♜ ")
Traceback (most recent call last):
File "jdoodle.py", line 1, in <module>
print("u265d u265e u265c ")
UnicodeEncodeError: 'ascii' codec can't encode character 'u265d' in position 0: ordinal not in range(128)
Command exited with non-zero status 1









share|improve this question



















  • 4




    It will let you use Unicode - and probably much more of Unicode than you're already using...
    – Toby Speight
    4 hours ago






  • 3




    Did you ask nicely? (What I mean is, how did you try? And how did it refuse? I know this isn't Stack Overflow, so the non-working code wouldn't be on-topic, but I'd be interested to know).
    – Toby Speight
    4 hours ago






  • 2




    Unicode is supposed to be available out-of-the-box. Example here.
    – Mathias Ettinger
    3 hours ago






  • 2




    Time to use a better IDE then: ideone.com/uK6XJ6
    – Mathias Ettinger
    2 hours ago






  • 2




    I'm not quite sure what the downvote is for... I've followed all of the rules for CR that I can tell.
    – FreezePhoenix
    1 hour ago












up vote
4
down vote

favorite









up vote
4
down vote

favorite











I wrote a basic menu application for my intro to python. I'm fairly new, and python does look promising. However, I am disappointed that it won't let me use Unicode.



the_burger = 16.99;
french_fries = 5.99;
currie_sauce = 19.99;
napkins_with_chocolates = 10.50;
juice_box = 89.01;
takeout = 18.99;
total = 0.0;
DONE = False
print("""
+-------------------------------------------+
| The Restaurant at the End of the Universe |
+---------------------------------+---------+
| AtThe "Big Boy" Burger | $""" + str(the_burger) + """ |
+---------------------------------+---------+
| BtFrench Fries | $""" + str(french_fries) + """ |
+---------------------------------+---------+
| CtCurrie sauce | $""" + str(currie_sauce) + """ |
+---------------------------------+---------+
| DtNapkins with Chocolates | $""" + str(napkins_with_chocolates) + str(0) + """ |
+---------------------------------+---------+
| EtJuice Box | $""" + str(juice_box) + """ |
+---------------------------------+---------+
| FtTakeout | $""" + str(takeout) + """ |
+---------------------------------+---------+
""");
while(not DONE):
print("Total:", total);
Item = input("Select a letter or 'done': ");
if Item is "A":
total += the_burger;
elif Item is "B":
total += french_fries;
elif Item is "C":
total += currie_sauce;
elif Item is "D":
total += napkins_with_chocolates;
elif Item is "E":
total += juice_box;
elif Item is "F":
total += takeout;
elif Item is "done":
print("Final total:", total);
DONE = True


The following is NOT intended for review, and is proof that it won't let me use unicode in python 3.6.5:



>>> print("♝ ♞ ♜ ")
Traceback (most recent call last):
File "jdoodle.py", line 1, in <module>
print("u265d u265e u265c ")
UnicodeEncodeError: 'ascii' codec can't encode character 'u265d' in position 0: ordinal not in range(128)
Command exited with non-zero status 1









share|improve this question















I wrote a basic menu application for my intro to python. I'm fairly new, and python does look promising. However, I am disappointed that it won't let me use Unicode.



the_burger = 16.99;
french_fries = 5.99;
currie_sauce = 19.99;
napkins_with_chocolates = 10.50;
juice_box = 89.01;
takeout = 18.99;
total = 0.0;
DONE = False
print("""
+-------------------------------------------+
| The Restaurant at the End of the Universe |
+---------------------------------+---------+
| AtThe "Big Boy" Burger | $""" + str(the_burger) + """ |
+---------------------------------+---------+
| BtFrench Fries | $""" + str(french_fries) + """ |
+---------------------------------+---------+
| CtCurrie sauce | $""" + str(currie_sauce) + """ |
+---------------------------------+---------+
| DtNapkins with Chocolates | $""" + str(napkins_with_chocolates) + str(0) + """ |
+---------------------------------+---------+
| EtJuice Box | $""" + str(juice_box) + """ |
+---------------------------------+---------+
| FtTakeout | $""" + str(takeout) + """ |
+---------------------------------+---------+
""");
while(not DONE):
print("Total:", total);
Item = input("Select a letter or 'done': ");
if Item is "A":
total += the_burger;
elif Item is "B":
total += french_fries;
elif Item is "C":
total += currie_sauce;
elif Item is "D":
total += napkins_with_chocolates;
elif Item is "E":
total += juice_box;
elif Item is "F":
total += takeout;
elif Item is "done":
print("Final total:", total);
DONE = True


The following is NOT intended for review, and is proof that it won't let me use unicode in python 3.6.5:



>>> print("♝ ♞ ♜ ")
Traceback (most recent call last):
File "jdoodle.py", line 1, in <module>
print("u265d u265e u265c ")
UnicodeEncodeError: 'ascii' codec can't encode character 'u265d' in position 0: ordinal not in range(128)
Command exited with non-zero status 1






python python-3.x






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago

























asked 4 hours ago









FreezePhoenix

513323




513323







  • 4




    It will let you use Unicode - and probably much more of Unicode than you're already using...
    – Toby Speight
    4 hours ago






  • 3




    Did you ask nicely? (What I mean is, how did you try? And how did it refuse? I know this isn't Stack Overflow, so the non-working code wouldn't be on-topic, but I'd be interested to know).
    – Toby Speight
    4 hours ago






  • 2




    Unicode is supposed to be available out-of-the-box. Example here.
    – Mathias Ettinger
    3 hours ago






  • 2




    Time to use a better IDE then: ideone.com/uK6XJ6
    – Mathias Ettinger
    2 hours ago






  • 2




    I'm not quite sure what the downvote is for... I've followed all of the rules for CR that I can tell.
    – FreezePhoenix
    1 hour ago












  • 4




    It will let you use Unicode - and probably much more of Unicode than you're already using...
    – Toby Speight
    4 hours ago






  • 3




    Did you ask nicely? (What I mean is, how did you try? And how did it refuse? I know this isn't Stack Overflow, so the non-working code wouldn't be on-topic, but I'd be interested to know).
    – Toby Speight
    4 hours ago






  • 2




    Unicode is supposed to be available out-of-the-box. Example here.
    – Mathias Ettinger
    3 hours ago






  • 2




    Time to use a better IDE then: ideone.com/uK6XJ6
    – Mathias Ettinger
    2 hours ago






  • 2




    I'm not quite sure what the downvote is for... I've followed all of the rules for CR that I can tell.
    – FreezePhoenix
    1 hour ago







4




4




It will let you use Unicode - and probably much more of Unicode than you're already using...
– Toby Speight
4 hours ago




It will let you use Unicode - and probably much more of Unicode than you're already using...
– Toby Speight
4 hours ago




3




3




Did you ask nicely? (What I mean is, how did you try? And how did it refuse? I know this isn't Stack Overflow, so the non-working code wouldn't be on-topic, but I'd be interested to know).
– Toby Speight
4 hours ago




Did you ask nicely? (What I mean is, how did you try? And how did it refuse? I know this isn't Stack Overflow, so the non-working code wouldn't be on-topic, but I'd be interested to know).
– Toby Speight
4 hours ago




2




2




Unicode is supposed to be available out-of-the-box. Example here.
– Mathias Ettinger
3 hours ago




Unicode is supposed to be available out-of-the-box. Example here.
– Mathias Ettinger
3 hours ago




2




2




Time to use a better IDE then: ideone.com/uK6XJ6
– Mathias Ettinger
2 hours ago




Time to use a better IDE then: ideone.com/uK6XJ6
– Mathias Ettinger
2 hours ago




2




2




I'm not quite sure what the downvote is for... I've followed all of the rules for CR that I can tell.
– FreezePhoenix
1 hour ago




I'm not quite sure what the downvote is for... I've followed all of the rules for CR that I can tell.
– FreezePhoenix
1 hour ago










1 Answer
1






active

oldest

votes

















up vote
2
down vote













Huge bug in 3.5.2



Entering done does nothing in Python 3.5.2, use == instead of is to fix this. In general is asks if two objects are the same object not if the contents are the same, this can give results different from what you expect for lists, so I suggest using == overall.



https://dbader.org/blog/difference-between-is-and-equals-in-python



Code repetition / Extensibility



A famous problem is code extensibility, it is quite inconvenient to add another item to the menu, also if you take a look at this list of ifs



 if Item is "A":
total += the_burger;
elif Item is "B":
total += french_fries;
elif Item is "C":
total += currie_sauce;
elif Item is "D":
total += napkins_with_chocolates;
elif Item is "E":
total += juice_box;
elif Item is "F":


you will notice that the only thing that happens is adding the cost to the total each time so there is a lot of repetition.



So let me explain a better solution.



I will use a list of tuples (pairs) of the form (food, price).



Than both the printing and the accounting of the money can be done from this data structure, you will only need to add another line inside and both printing and accounting will be generated automatically.



I left out the proper printing alignement as an exercise for the reader, resource: https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces



Code with didactic comments: (real code would not be commented so much)



# It would be better to import this from string/ascii library
ALPHABET = "ABCDEFGHILMNOPQRSTUVZ"


FOOD_WITH_PRICES = [
("Apple", 0.5),
("Ham", 4),
("Bread", 1)
]

# for x in list: is standard syntax to iterate over a list, x becomes progressively equal to each element
# enumerate adds the index to each element
def print_stilish_menu(food_with_prices):
print("""
+-------------------------------------------+
| The Restaurant at the End of the Universe |
+---------------------------------+---------+""")
for (index, (food, price)) in enumerate(food_with_prices):
print("""
| lettertThe "food" | $ price |
+---------------------------------+---------+
""".format(letter=ALPHABET[index], food=food, price=price))

# list[:n] means the first n elements of a list
# for more info look for `python list slice`
print_stilish_menu(FOOD_WITH_PRICES)
total = 0
while(True):
print("Total:", total);
x = input("Select a letter or 'done': ")
if x in ALPHABET[:len(FOOD_WITH_PRICES)]:
total += FOOD_WITH_PRICES[ALPHABET.index(x)][1]
elif x == 'done':
break
# Some kind of message if the input is invalid
# is good practice
else:
print("Invalid Input")
print("You spent ".format(total))





share|improve this answer






















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "196"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f205155%2frestaurant-at-the-end-of-the-universe%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    Huge bug in 3.5.2



    Entering done does nothing in Python 3.5.2, use == instead of is to fix this. In general is asks if two objects are the same object not if the contents are the same, this can give results different from what you expect for lists, so I suggest using == overall.



    https://dbader.org/blog/difference-between-is-and-equals-in-python



    Code repetition / Extensibility



    A famous problem is code extensibility, it is quite inconvenient to add another item to the menu, also if you take a look at this list of ifs



     if Item is "A":
    total += the_burger;
    elif Item is "B":
    total += french_fries;
    elif Item is "C":
    total += currie_sauce;
    elif Item is "D":
    total += napkins_with_chocolates;
    elif Item is "E":
    total += juice_box;
    elif Item is "F":


    you will notice that the only thing that happens is adding the cost to the total each time so there is a lot of repetition.



    So let me explain a better solution.



    I will use a list of tuples (pairs) of the form (food, price).



    Than both the printing and the accounting of the money can be done from this data structure, you will only need to add another line inside and both printing and accounting will be generated automatically.



    I left out the proper printing alignement as an exercise for the reader, resource: https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces



    Code with didactic comments: (real code would not be commented so much)



    # It would be better to import this from string/ascii library
    ALPHABET = "ABCDEFGHILMNOPQRSTUVZ"


    FOOD_WITH_PRICES = [
    ("Apple", 0.5),
    ("Ham", 4),
    ("Bread", 1)
    ]

    # for x in list: is standard syntax to iterate over a list, x becomes progressively equal to each element
    # enumerate adds the index to each element
    def print_stilish_menu(food_with_prices):
    print("""
    +-------------------------------------------+
    | The Restaurant at the End of the Universe |
    +---------------------------------+---------+""")
    for (index, (food, price)) in enumerate(food_with_prices):
    print("""
    | lettertThe "food" | $ price |
    +---------------------------------+---------+
    """.format(letter=ALPHABET[index], food=food, price=price))

    # list[:n] means the first n elements of a list
    # for more info look for `python list slice`
    print_stilish_menu(FOOD_WITH_PRICES)
    total = 0
    while(True):
    print("Total:", total);
    x = input("Select a letter or 'done': ")
    if x in ALPHABET[:len(FOOD_WITH_PRICES)]:
    total += FOOD_WITH_PRICES[ALPHABET.index(x)][1]
    elif x == 'done':
    break
    # Some kind of message if the input is invalid
    # is good practice
    else:
    print("Invalid Input")
    print("You spent ".format(total))





    share|improve this answer


























      up vote
      2
      down vote













      Huge bug in 3.5.2



      Entering done does nothing in Python 3.5.2, use == instead of is to fix this. In general is asks if two objects are the same object not if the contents are the same, this can give results different from what you expect for lists, so I suggest using == overall.



      https://dbader.org/blog/difference-between-is-and-equals-in-python



      Code repetition / Extensibility



      A famous problem is code extensibility, it is quite inconvenient to add another item to the menu, also if you take a look at this list of ifs



       if Item is "A":
      total += the_burger;
      elif Item is "B":
      total += french_fries;
      elif Item is "C":
      total += currie_sauce;
      elif Item is "D":
      total += napkins_with_chocolates;
      elif Item is "E":
      total += juice_box;
      elif Item is "F":


      you will notice that the only thing that happens is adding the cost to the total each time so there is a lot of repetition.



      So let me explain a better solution.



      I will use a list of tuples (pairs) of the form (food, price).



      Than both the printing and the accounting of the money can be done from this data structure, you will only need to add another line inside and both printing and accounting will be generated automatically.



      I left out the proper printing alignement as an exercise for the reader, resource: https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces



      Code with didactic comments: (real code would not be commented so much)



      # It would be better to import this from string/ascii library
      ALPHABET = "ABCDEFGHILMNOPQRSTUVZ"


      FOOD_WITH_PRICES = [
      ("Apple", 0.5),
      ("Ham", 4),
      ("Bread", 1)
      ]

      # for x in list: is standard syntax to iterate over a list, x becomes progressively equal to each element
      # enumerate adds the index to each element
      def print_stilish_menu(food_with_prices):
      print("""
      +-------------------------------------------+
      | The Restaurant at the End of the Universe |
      +---------------------------------+---------+""")
      for (index, (food, price)) in enumerate(food_with_prices):
      print("""
      | lettertThe "food" | $ price |
      +---------------------------------+---------+
      """.format(letter=ALPHABET[index], food=food, price=price))

      # list[:n] means the first n elements of a list
      # for more info look for `python list slice`
      print_stilish_menu(FOOD_WITH_PRICES)
      total = 0
      while(True):
      print("Total:", total);
      x = input("Select a letter or 'done': ")
      if x in ALPHABET[:len(FOOD_WITH_PRICES)]:
      total += FOOD_WITH_PRICES[ALPHABET.index(x)][1]
      elif x == 'done':
      break
      # Some kind of message if the input is invalid
      # is good practice
      else:
      print("Invalid Input")
      print("You spent ".format(total))





      share|improve this answer
























        up vote
        2
        down vote










        up vote
        2
        down vote









        Huge bug in 3.5.2



        Entering done does nothing in Python 3.5.2, use == instead of is to fix this. In general is asks if two objects are the same object not if the contents are the same, this can give results different from what you expect for lists, so I suggest using == overall.



        https://dbader.org/blog/difference-between-is-and-equals-in-python



        Code repetition / Extensibility



        A famous problem is code extensibility, it is quite inconvenient to add another item to the menu, also if you take a look at this list of ifs



         if Item is "A":
        total += the_burger;
        elif Item is "B":
        total += french_fries;
        elif Item is "C":
        total += currie_sauce;
        elif Item is "D":
        total += napkins_with_chocolates;
        elif Item is "E":
        total += juice_box;
        elif Item is "F":


        you will notice that the only thing that happens is adding the cost to the total each time so there is a lot of repetition.



        So let me explain a better solution.



        I will use a list of tuples (pairs) of the form (food, price).



        Than both the printing and the accounting of the money can be done from this data structure, you will only need to add another line inside and both printing and accounting will be generated automatically.



        I left out the proper printing alignement as an exercise for the reader, resource: https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces



        Code with didactic comments: (real code would not be commented so much)



        # It would be better to import this from string/ascii library
        ALPHABET = "ABCDEFGHILMNOPQRSTUVZ"


        FOOD_WITH_PRICES = [
        ("Apple", 0.5),
        ("Ham", 4),
        ("Bread", 1)
        ]

        # for x in list: is standard syntax to iterate over a list, x becomes progressively equal to each element
        # enumerate adds the index to each element
        def print_stilish_menu(food_with_prices):
        print("""
        +-------------------------------------------+
        | The Restaurant at the End of the Universe |
        +---------------------------------+---------+""")
        for (index, (food, price)) in enumerate(food_with_prices):
        print("""
        | lettertThe "food" | $ price |
        +---------------------------------+---------+
        """.format(letter=ALPHABET[index], food=food, price=price))

        # list[:n] means the first n elements of a list
        # for more info look for `python list slice`
        print_stilish_menu(FOOD_WITH_PRICES)
        total = 0
        while(True):
        print("Total:", total);
        x = input("Select a letter or 'done': ")
        if x in ALPHABET[:len(FOOD_WITH_PRICES)]:
        total += FOOD_WITH_PRICES[ALPHABET.index(x)][1]
        elif x == 'done':
        break
        # Some kind of message if the input is invalid
        # is good practice
        else:
        print("Invalid Input")
        print("You spent ".format(total))





        share|improve this answer














        Huge bug in 3.5.2



        Entering done does nothing in Python 3.5.2, use == instead of is to fix this. In general is asks if two objects are the same object not if the contents are the same, this can give results different from what you expect for lists, so I suggest using == overall.



        https://dbader.org/blog/difference-between-is-and-equals-in-python



        Code repetition / Extensibility



        A famous problem is code extensibility, it is quite inconvenient to add another item to the menu, also if you take a look at this list of ifs



         if Item is "A":
        total += the_burger;
        elif Item is "B":
        total += french_fries;
        elif Item is "C":
        total += currie_sauce;
        elif Item is "D":
        total += napkins_with_chocolates;
        elif Item is "E":
        total += juice_box;
        elif Item is "F":


        you will notice that the only thing that happens is adding the cost to the total each time so there is a lot of repetition.



        So let me explain a better solution.



        I will use a list of tuples (pairs) of the form (food, price).



        Than both the printing and the accounting of the money can be done from this data structure, you will only need to add another line inside and both printing and accounting will be generated automatically.



        I left out the proper printing alignement as an exercise for the reader, resource: https://stackoverflow.com/questions/5676646/how-can-i-fill-out-a-python-string-with-spaces



        Code with didactic comments: (real code would not be commented so much)



        # It would be better to import this from string/ascii library
        ALPHABET = "ABCDEFGHILMNOPQRSTUVZ"


        FOOD_WITH_PRICES = [
        ("Apple", 0.5),
        ("Ham", 4),
        ("Bread", 1)
        ]

        # for x in list: is standard syntax to iterate over a list, x becomes progressively equal to each element
        # enumerate adds the index to each element
        def print_stilish_menu(food_with_prices):
        print("""
        +-------------------------------------------+
        | The Restaurant at the End of the Universe |
        +---------------------------------+---------+""")
        for (index, (food, price)) in enumerate(food_with_prices):
        print("""
        | lettertThe "food" | $ price |
        +---------------------------------+---------+
        """.format(letter=ALPHABET[index], food=food, price=price))

        # list[:n] means the first n elements of a list
        # for more info look for `python list slice`
        print_stilish_menu(FOOD_WITH_PRICES)
        total = 0
        while(True):
        print("Total:", total);
        x = input("Select a letter or 'done': ")
        if x in ALPHABET[:len(FOOD_WITH_PRICES)]:
        total += FOOD_WITH_PRICES[ALPHABET.index(x)][1]
        elif x == 'done':
        break
        # Some kind of message if the input is invalid
        # is good practice
        else:
        print("Invalid Input")
        print("You spent ".format(total))






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 49 mins ago

























        answered 54 mins ago









        Caridorc

        22.8k433113




        22.8k433113



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f205155%2frestaurant-at-the-end-of-the-universe%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery