mac系统运行python程序_我的mac终端不能运行python函数

我尝试在mac终端上运行多个python函数,对于这个程序,它们都返回语法错误def spam():

print "R"

spam()

它返回错误:

^{pr2}$

这是我能找到的最简单的函数。在

为了清楚一点,终端正在运行程序的其余部分,但它不能处理函数。在#!/usr/bin/python

import math

number = int(raw_input("What's your surd?"))

print type(number)

#Just to let us know what the input is

if type(number) == int:

print "Number is an integer"

else:

print "Please enter a number"

value = math.sqrt(number)

#Takes the number and square roots it

new_value = int(value)

#Turns square root of number into an integer

if type(new_value) == int:

print "Surd can be simplified"

print new_value

else:

print "Surd cannot be simplified"

print value

这个程序运行良好,即使它现在有点错误,但下面的程序返回与前一个函数相同的错误。在# define a function

def print_factors(x):

print("The factors of",x,"are:")

for i in range(1, x + 1):

if x % i == 0:

print(i)

num = int(input("What's your number? "))

print_factors(num)

为什么终端在没有语法错误的地方返回语法错误?在