15,943,623 members
1.00/5 (1 vote)
See more:
I am doing beginner Python exercises, have never coded before.

I want to know why it doesn't work if I move part of the code inside the function (I already know it works if I write it before). specifically this part:
Python
```num_1 = input("first number: ")
num_2 = input("second number: ")
int(num_1)
int(num_2)```

What I have tried:

Python
```def multiplication_or_division(num_1, num_2):
num_1 = input("first number: ")
num_2 = input("second number: ")
int(num_1)
int(num_2)
if num_1 * num_2 <= 1000:
print(num_1 * num_2)
else:
print(num_1 + num_2)

multiplication_or_division(int(num_1), int(num_2))```
Posted
Updated 12-Sep-23 9:25am
v3
Patrice T 9-Sep-23 0:15am
-What supposed to do ypur code ?
-What input fives you what output?
-What output did you expected ?
Use Improve question to update your question.

## Solution 1

You've defined `multiplication_or_division` to take two parameters, but when you call it:
Python
`multiplication_or_division(int(num_1), int(num_2))`
you try to pass it variables which don't exist - `num_1` and `num_2` are declared as the parameters to the `multiplication_or_division` function and only exists inside that function - you are supposed to pass them into the function so it can process them:
Python
```def multiplication_or_division(num_1, num_2):
if num_1 * num_2 <= 1000:
print(num_1 * num_2)
else:
print(num_1 + num_2)

num_1 = input("first number: ")
num_2 = input("second number: ")
multiplication_or_division(int(num_1), int(num_2))```
Or not pass them as parameters:
Python
```def multiplication_or_division():
num_1 = int(input("first number: "))
num_2 = int(input("second number: "))
if num_1 * num_2 <= 1000:
print(num_1 * num_2)
else:
print(num_1 + num_2)

multiplication_or_division()```