开发者

Syntax Error when trying to define multiple functions in python?

开发者 https://www.devze.com 2023-03-26 12:02 出处:网络
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

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 num开发者_JS百科ber
            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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消