Paremeter passing
tdudek (3)

I'm messing around with parameter passing in functions. The total is not being correctly passed here. What is the problem?

You are viewing a single comment. View All
Answered by heyitsmarcus (287) [earned 5 cycles]
View Answer
heyitsmarcus (287)

@tdudek When you're passing variables between modules, what you want to do is return values from that module back to the main script so that they can be used. In this case, you don't need the global keyword to store the values. needs to be changed slightly and needs to be changed slightly. will call input_module and then get those values back from the input_module's returned values.

Here's a repl I made from your code:

#Developed on 28 June 2019

#importing the modules
import input_module
import product_module

#Main Program
#Setting all variables to zero

#Calling the modules
#Only change here is that num1, num2 get the values back from the called module
num1, num2 = input_module.InputNums()
product_module.CalculateProduct(num1, num2)

def InputNums():
  #remove all parameters and use global num1, num2 to store value
  #this way num1 and num2 can be used in the next function
  #global num1,num2
  num1=int(input("Enter the first number: "))
  num2=int(input("Enter the second number: "))
  #And the module now returns those values
  return num1, num2