2012-12-05 77 views
1

嘿,大家我介绍python编程,我们正在做第一个独立的代码。分配如下:UnboundLocalError:分配前引用的局部变量'print'

Prompt the user for his or her name. Then prompt the user for two numbers and then perform a mathematical operation of your choice on them. Make sure the program works with decimal numbers, and that you print a full equation in response, not just the result: Enter a number: 2.3 Enter another number: 3.6 2.3 – 3.6 = -1.3

所以我进入:

def main1(): 
print("This is program 1!") 
name = input("Please enter your name: ") 
print("Pleased to meet you,", name ,"!") #next line def main2(): 
print("This is program 2!") 
import math 
number = input("Enter a number: ") 
number = float(number) 
numberr = input("Enter another number: ") 
numberr = float(numberr) 
print = ("number + numberr") 

我不停的得到这个:

UnboundLocalError: local variable 'print' referenced before assignment 

帮助!

+0

[Python变量范围错误(可能的重复http://stackoverflow.com/questions/370357/python-可变范围错误) –

+0

Stack Overflow上有'UnboundLocalError'的重复项。屏幕的右侧应显示至少10个。 –

回答

4

您尝试将值分配给print

您写道:

print = ("number + numberr") 

但你实际上的意思是:

print(number + numberr) 
+3

我会补充一句,如果您从“Traceback”开始读取/发布完整回溯,您将更容易找到问题所在(并在遇到异常时从其他人​​处获得帮助)。回溯告诉你你的问题是哪一行代码。 – Iguananaut

+0

omg非常感谢你 – user1880690

相关问题