0

Hey everyone I'm in intro python programming and we're doing out first independent code. The assignment is as follows:

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

So I entered:

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")

And I keep on getting this:

UnboundLocalError: local variable 'print' referenced before assignment

Help!!

user1880690
  • 31
  • 3
  • 5
  • Possible duplicate of [Python variable scope error](http://stackoverflow.com/questions/370357/python-variable-scope-error) – Kevin J. Chase May 15 '16 at 06:45
  • There are a _lot_ of duplicates for `UnboundLocalError` on Stack Overflow. The right side of your screen should show at least ten of them. – Kevin J. Chase May 15 '16 at 06:48

1 Answers1

4

You try to assign a value to print.

You wrote:

print = ("number + numberr")

But you in fact meant:

print(number + numberr)
Sebastian Paaske Tørholm
  • 49,493
  • 11
  • 100
  • 118
  • 3
    I'll add, you'd have an easier time finding what your problem is (and getting help from others when encountering an exception) if you read/post the full traceback starting from "Traceback". Tracebacks tell you what line of code your problem is on. – Iguananaut Dec 05 '12 at 22:51