-9

Hello I am beginner to python and am trying to learn, this is what i keep hitting when i execute the below code, where is the mistake

#!/usr/bin/python

def main():
num1=input("Enter the 1st #\t\t")
print "First # is\t:", num1
print
num2=input("Enter the 2nd #\t\t")
print "Second # is\t:",num2
print
num3=input("Enter the 3rd #\t\t")
print "3rd #is:,\t",num3
if(num1>num2) and (num1>num3):
    print"Highest # is:\t",num1
elif(num2>num3) and (num2 >num1):
    print"Highest # is:\t",num2
else:
    print "The WINNER IS\n"
    print num3

main()

Error:

python 1.py
File "1.py", line 4
num1=input("Enter the 1st #\t\t")
   ^
IndentationError: expected an indented block

Where is the indentation that i am missing?

ady6831983
  • 113
  • 1
  • 8
  • 5
    Almost all of it, currently. Your question had no indentation to put any code inside the `def main()` block/scope. If this is an accurate representation of your code, you need to indent everything that you intend to be part of `main` by 4 spaces – roganjosh Oct 04 '16 at 20:46
  • @raganjosh what do you mean, can you correct the above syntax? – ady6831983 Oct 04 '16 at 20:48
  • 3
    @ady6831983 Surely any Python book/ tutorial would explain that any code in a function definition needs to be indented. – John Coleman Oct 04 '16 at 20:50
  • Please see my edited comment. Indentation is important in Python... everything you want to be contained within the function `main()` should be indented, preferably by 4 spaces. – roganjosh Oct 04 '16 at 20:50
  • 1
    Welcome to coding in python! – Preston Martin Oct 04 '16 at 20:53
  • Python is great for beginners because it forces you to indent. Python is terrible for beginners with experience in languages which don't require indentation, because they've learned bad habits and assume that every language is identical. – Nic Oct 04 '16 at 21:01
  • Possible duplicate of [Python def function: How do you specify the end of the function?](http://stackoverflow.com/questions/1573548/python-def-function-how-do-you-specify-the-end-of-the-function) – Petter Friberg Oct 04 '16 at 21:03

4 Answers4

2

You should indent your main function with spaces or tabs. (4 spaces is recommanded)

Like this:

def main()
    num=input()
    # rest of your main code

main()

I saw you already did this for if/else, you should also do it for functions.

I recommend you take a beginner python course like the one of codecademy.

Tristan
  • 2,000
  • 17
  • 32
2

You will make an indention to Main function, I rewrite your code here:

Leading whitespace (spaces and tabs) at the beginning of a logical line is used to compute the indentation level of the line, which in turn is used to determine the grouping of statements.

you can use of Python doc. to learn more about Python and also the use of an IDE such as ATOM or PyCharm to make better coding.

def main():
   num1=input("Enter the 1st #\t\t")
   print "First # is\t:", num1
   print
   num2=input("Enter the 2nd #\t\t")
   print "Second # is\t:",num2
   print
   num3=input("Enter the 3rd #\t\t")
   print "3rd #is:,\t",num3
   if(num1>num2) and (num1>num3):
       print"Highest # is:\t",num1
   elif(num2>num3) and (num2 >num1):
       print"Highest # is:\t",num2
   else:
       print "The WINNER IS\n"
       print num3

main()
Saeed Rahmani
  • 650
  • 1
  • 8
  • 29
2

Indent the code.

In python, you always have to indent code after a colon (:) otherwise it does not know what order to execute it in. Just indent everything after def main():

674 3393
  • 21
  • 3
1

All of your code under def main(): should be indented except the line when you calling main()