Python Forum
python wont recognize indentation
Thread Rating:
  • 3 Vote(s) - 2.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python wont recognize indentation
#1
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))
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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]
Reply
#4
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
OMG

I cant believ it! I feel sooo stupid! Thank to all!
Reply
#6
(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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Yeah sure will do that in the future! Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  under VS Code: the terminal does not recognize "1+1" as a command Rahzan 4 60 May-01-2026, 01:53 PM
Last Post: Rahzan
  Why wont this path work one way, but will the other way? cubangt 2 1,936 Sep-01-2023, 04:14 PM
Last Post: cubangt
  python cant recognize PIP siubikYT 2 7,658 Jul-19-2023, 06:30 PM
Last Post: Lahearle
  Is it possible to make a program recognize how many clicks it has had on the monitor? jao 0 2,005 Feb-25-2022, 06:31 PM
Last Post: jao
  My program won't recognize the filename. braingoblins 1 2,177 Jan-07-2022, 06:18 PM
Last Post: deanhystad
Star NameError – function doesn't recognize imported modules Sir 4 8,402 Dec-01-2020, 06:36 AM
Last Post: Sir
Bug Python Shell 3.9.0 - Issue with indentation Earis 17 13,186 Oct-31-2020, 07:00 AM
Last Post: Earis
  Player object wont recognize collision with other objects. Jan_97 3 4,648 Dec-22-2019, 04:08 PM
Last Post: joe_momma
  When I import a Module it wont run PyNovice 17 11,411 Oct-26-2019, 11:14 AM
Last Post: PyNovice
  How to recognize space or enter as one-character input? Mark17 5 11,085 Oct-17-2019, 08:19 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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