Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aaronvan

Suspended
Original poster
Dec 21, 2011
1,350
9,353
República Cascadia
I have two functions:
Code:
def userInput():
	num1 = str(input("Enter a Roman numeral: ")) # get first Roman numeral input from user
	firstNum = decimalTrans(num1)	        # pass the input to be converted
	print("The first number is: ", firstNum)	   # print the decimal
		
	num2 = str(input("Enter another Roman numeral: "))
	secondNum = decimalTrans(num2)
	print("The second number is: ", secondNum)

and

Code:
def mathAction(): # takes two inputs and performs arithmetic on them
	operation = str(input("Enter your desired arithmetic operation: "))
	if operation == '+':
		sum = firstNum + secondNum
		print("The sum is:",reConvert(sum),"(",sum,")")
	elif operation == '-':
		difference = firstNum - secondNum
		print("The difference is",reConvert(difference),"(",difference,")")
	elif operation == '*':
		product = firstNum * secondNum
		print("The product is",reConvert(product),"(",product,")")
	elif operation == '//' or '/':
		quotient = firstNum // secondNum
		print("The quotient is",reConvert(quotient),"(",quotient,")")
	else:
		print("Enter a correct arithmetic operator.")

I want to pass the decimal values of firstNum and secondNum from userInput to the function mathAction. I've tried both positional and keywords, but I'm just not seeing something. I'm sure it's right in front of my face but I'm stumped. Yea, this is for school but this is just a small portion of my overall program. I have the rest of it working pretty good.
 
Well, here is what I did:

Code:
def userInput():
	num1 = str(input("Enter a Roman numeral: ")) # get the first input from user
	print("The first number is: ", decimalTrans(num1))	   # print the decimal
	firstNum = decimalTrans(num1)
	
	num2 = str(input("Enter another Roman numeral: ")) # get the second input
	print("The second number is: ", decimalTrans(num2))   # print the decimal
	secondNum = decimalTrans(num2)
	
	return firstNum, secondNum  # return both decimal numbers

Code:
def mathAction():
	firstNum, secondNum = userInput()
...
...
...

I thought by just calling the function userInput(), return firstNum and secondNum would be automatically recognized by the calling function. I didn't realize I had to assign the variables to userInput(). :D
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.