Home > Mobile >  Print function not printing in order
Print function not printing in order

Time:02-17

print('*'*11,'Welcome to Salad Bar','*'*11,'\n')
print('\t1.Order Salad')
print('\t2.checkout')      
print('\t3.Quit')
option = input('Select your option(1-4): \n')
if option == 1:
    print('Salad menu\n1.Vegetarian-$10.99\n2.Seafood-16.99\n3.Protein-14.99')

When I ran the code, here is the output

Select your option(1-4): 
*********** Welcome to Salad Bar *********** 

    1.Order Salad
    2.checkout
    3.Quit

Not sure why the "welcome to salad bar...." is not printed first.

CodePudding user response:

Can you specify the version of python you're running? I'm on 3.7.4 and cannot seem to recreate


*********** Welcome to Salad Bar *********** 

1.Order Salad
2.checkout
3.Quit
Select your option(1-4): 

CodePudding user response:

I tried running your code in VS Code, in Jupyter Notebook, and from a Windows command prompt. In all three cases, I got the 'Welcome to Salad Bar' line first, as you expected. So there might be something wrong with your Python setup.

If you are not using an environment such as VS Code, that highlights tricky errors such as not-quite-right indentation and such, I suggest that you do so. I have found this very helpful, and it might help you here. VS Code is free and was recommended by a friend, and there are other free environments and editors out there with similar features.

There is also one small issue with your code: The "if option == 1" clause will never be True because the input command returns a string. It will work if you say this:

if option == str(1):

  • Eliot

P.S. I see that you are new to Stackoverflow. Me too! This is the first time I have offered an answer. Hope it was helpful.

  • Related