Python Forum

Full Version: python wont recognize indentation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

My problem is as follows:

In the python 3.6 program, I have my code. Every thing works fine right up until line 94 (here its on line 28) where for some reason when I hit ENTER after the ':' at the end of an 'if' statement, the indentation seems to be off set. Below you can see that I have indented it correctly, but even when I do so in python, it still highlights the ':'. I'm wondering if I might have touched something on the FORMAT tab up-top.

Is this possible?

def my_pizza():
    print('\nGreat! Please select your pizza by imputting\nthe corresponding number?\n')
    time.sleep(2)
    for i, t in pizzas.items():
        print(i + ': ' + t)          # shows pizza list

        pizza = input()

    while pizza not in pizzas.keys():
        print('that is not an option')
        
        pizza = input()
        
    if pizza in pizzas.keys():
        print('You have chosen a ' + pizzas[str(pizza)])
        time.sleep(2)
        order.setdefault('Pizza', pizzas[str(pizza)])         # pizza select successful
        print('Enter Quantity')
        
        qty = input()
    
    while int(qty) <= 0:

        print('That is not a number')

    qty = int(input('Enter Quantity')

    if int(qty) == 1:                      [b]# THIS LINE GIVES ERROR AND HIGHLIGHTS ':'[/b]
        print('You have ordered ' + str(qty) + ' ' + pizzas[str(pizza)])
        time.sleep(2)
        order.setdefault('Qty', str(qty))

    elif qty >= 2:
        print('You have ordered ' + str(qty) + ' ' + pizzas[str(pizza)] + 's')
        time.sleep(2)
        order.setdefault('Qty', str(qty))
you are missing closing parenthesis on the line just above that one (#26)
Please, always post the entire traceback that you get. We need to see the whole thing.
Take a time to read What to include in a post
You are missing a ) here:

qty = int(input('Enter Quantity'))
And the [b] is part of your script, just pass it to the comment:

    if int(qty) == 1:                      # [b] THIS LINE GIVES ERROR AND HIGHLIGHTS ':'[/b]
(Jul-06-2018, 10:44 AM)gontajones Wrote: [ -> ]And the [b] is part of your script
they just want to make the comment bold, it's not part of the original script
OMG

I cant believ it! I feel sooo stupid! Thank to all!
(Jul-06-2018, 10:47 AM)JWhykes Wrote: [ -> ]I cant believ it! I feel sooo stupid! Thank to all!
if it was problem with the indentation you will get IndentationError. In this case you get SyntaxError. That's why it's important to read/post full traceback. And learn to understand it
Yeah sure will do that in the future! Thanks