-1

I'm learning python, and I'm trying with a set of exercises, but I'm stuck on the next one:

     inp_1 = input('your score between 0.0 and 1.0')

        try:   
score = float(inp_1)   
if 0.9 <= score <= 1.0:
              print ("A")    elif score >= 0.8:
              print ("B")    elif score >= 0.7:
              print ("C")    elif score >= 0.6:
              print ("D")    elif score <  0.6:
              print ("Your grade is an F")    
    else:       
print ('your score is more than 1.0')  
    except:   
 print ('invalid input, please try with a number')

but I'm get the next message error:

IndentationError: unindent does not match any outer indentation level on line 7 elif score >= 0.8: ^ in main.py
  • It's normal for new python users to get confused with indentation, please refer to [this answer](https://stackoverflow.com/a/29636895/797495) to fix the current script indentation. – Pedro Lobito Dec 10 '18 at 19:15

2 Answers2

0

The indentation (= number of tabs / spaces in front of each line) is important in python. The code you posted isn't indented properly. A correct indentation would look like this:

inp_1 = input('your score between 0.0 and 1.0')

try:   
    score = float(inp_1)   
    if 0.9 <= score <= 1.0:
        print ("A")    
    elif score >= 0.8:
        print ("B")
    elif score >= 0.7:
        print ("C")
    elif score >= 0.6:
        print ("D")    
    elif score <  0.6:
        print ("Your grade is an F")    
    else:       
        print ('your score is more than 1.0')  
except:   
    print ('invalid input, please try with a number')

The first line is always un-indented. When starting a block (e.g. try:, if:, elif:, ...), all following lines that belong within this block are indented with 4 spaces more than the opening line. "Closing" a block is done by writing the next statement with less indentation.

Another example:

if False:
    print(1)
    print(2)
# prints nothing because both print statements are part of the if condition

if False:
    print(1)
print(2)
# prints 2 because the `print(2)` statement is not part of the if condition

Does this answer your question?

Felix
  • 6,131
  • 4
  • 24
  • 44
0

Your indentations should be like this:

inp_1 = input('your score between 0.0 and 1.0')
try:
    score = float(inp_1)
    if 0.9 <= score <= 1.0:
        print ("A")    
    elif score >= 0.8:
        print ("B")    
    elif score >= 0.7:
        print ("C")    
    elif score >= 0.6:
        print ("D")    
    elif score <  0.6:
        print ("Your grade is an F")
    else:
        print ('your score is more than 1.0')
except:
    print ('invalid input, please try with a number')

I think you didn't understand indentations fully. This isn't like any other languages. You need to make indentations correctly.

Hope it will help you

jan Sena
  • 31
  • 1
  • 8