2012-12-05 5 views
1

안녕하세요, 저는 모두 intro 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

가능한 중복 http://stackoverflow.com/questions/370357/python- variable-scope-error) –

+0

Stack Overflow에서'UnboundLocalError'에 대해 _lot_ 개의 중복이 있습니다. 화면의 오른쪽에는 최소한 10 개가 표시되어야합니다. –

답변

4

print에 값을 지정하려고합니다.

당신이 쓴 :

print = ("number + numberr") 

그러나 사실은 의미 :

print(number + numberr) 
[파이썬 변수 범위 오류 (의
+3

"Traceback"에서 시작하여 전체 추적을 읽거나 게시하는 경우 문제가 무엇인지 파악하고 예외가 발생하면 다른 사람의 도움을 얻는 것이 더 쉽습니다. Tracebacks는 문제의 코드 행을 알려줍니다. – Iguananaut

+0

감사합니다. – user1880690

관련 문제