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.
精彩评论