Passing arguments in Python3

Discussion in 'Mac Programming' started by aaronvan, Nov 8, 2014.

  1. aaronvan Suspended

    aaronvan

    Joined:
    Dec 21, 2011
    Location:
    República Cascadia
    #1
    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.
     
  2. subsonix macrumors 68040

    Joined:
    Feb 2, 2008
    #2
  3. aaronvan, Nov 10, 2014
    Last edited: Nov 10, 2014

    aaronvan thread starter Suspended

    aaronvan

    Joined:
    Dec 21, 2011
    Location:
    República Cascadia
    #3
    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
     

Share This Page