1

I'm trying to learn python, so I'm just writing some simple programs. I wrote these two bits of code to define two of the functions I want to use in the program, and they both do what they want but when I try to paste them into IDLE it says there is a syntax error at the second def. Any idea what this is?

here's the code:

def print_seq1(number):

    number = input("Pick a number: ")

    print " "
    while number != 1:
        if number%2==0:
            print number
            number = number/2
        else:
            print number
            number = number*3 + 1
    print number
    print " "
    choice = 0  

def print_seq2(number):

        number = input("Pick a number: ")
        print " "
        while number != 1:
            if number%2==0:
                print number,
                number = number/2
            else:
                print number,
                number = number*3 + 1
        print number
        print " "
        choice = 0
4
  • Where exactly is the syntax error? Commented Aug 4, 2011 at 18:18
  • Indentation problem, I assume? Commented Aug 4, 2011 at 18:20
  • Copy/pasting this into IDLE, I get no syntax error Commented Aug 4, 2011 at 18:20
  • Ii should be clarified that probably the OP means idle python shell, where I could reproduce the error, but not the idle python editor where no syntax error is produced Commented Dec 3, 2011 at 8:34

2 Answers 2

1

Interactive interpreters (a.k.a. REPL, just "interpreter", and many other terms) usually expect only a single top-level statement (a function definition, a class definition, a global assignment, a loop, ...) at a time. You give it two and it's confused. Try putting in the first def, a blank line to confirm and actually run your input, then the second def.

Sign up to request clarification or add additional context in comments.

Comments

0

When you paste, you mess up the formatting of the code, either re-indent correctly after pasting or paste functions seperately.

1 Comment

Wrong indentation is strictly speaking a syntax error too, but since it is explicitly labeled differently in error messages, I tend not to assume indentation errors when people speak of syntax errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.