Is there any mistake in this Code ? if it is let me know?
a = int(input("Enter Your First Number=")) b = int(input("\nEnter Your Second Number=")) def cal(): sum = a + b sub = a - b mul = a * b div = a % b cal() print("\nAddtion of Two Number is =" , sum) print("\nSubtraction of Two Number is =" , sub ) print("\nMultiplication of Two Number is =" , mul ) print("\nDivision of Two Number is =" , div )
I can’t find the exact output I’m a beginner So guide me please,
You need to make the function return the values:
a = int(input("Enter Your First Number=")) b = int(input("\nEnter Your Second Number=")) def cal(): sum = a + b sub = a - b mul = a * b div = a % b return sum, sub, mul, div sum, sub, mul, div = cal() print("\nAddtion of Two Number is =" , sum) print("\nSubtraction of Two Number is =" , sub ) print("\nMultiplication of Two Number is =" , mul ) print("\nDivision of Two Number is =" , div )
You have to return the values in order to use them outside the function
a = int(input("Enter Your First Number=")) b = int(input("\nEnter Your Second Number=")) def cal(): return a + b, a - b, a * b, a % b sum,sub,mul,div = cal() print("\nAddtion of Two Number is =" , sum) print("\nSubtraction of Two Number is =" , sub ) print("\nMultiplication of Two Number is =" , mul ) print("\nDivision of Two Number is =" , div )
You cant acces function variables outside of function. PLace print statements inside a function or return values from the function as mentioned below.