Oskar
Oskar

Reputation: 11

Syntax Error when trying to define multiple functions in python?

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

Upvotes: 1

Views: 2775

Answers (2)

anijhaw
anijhaw

Reputation: 9402

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

Upvotes: 0

user395760
user395760

Reputation:

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.

Upvotes: 1

Related Questions