Please help me why on executing the below program an error coming on m variable
x=int(input("Enter first number"))
y=int(input("Enter second number"))
def multiplication():
m=x*y
print("Multiplication result"m)
Please help me why on executing the below program an error coming on m variable
x=int(input("Enter first number"))
y=int(input("Enter second number"))
def multiplication():
m=x*y
print("Multiplication result"m)
In Python 2, you should accept user inputs with raw_input()
: Check this.
x=int(raw_input("Enter first number"))
y=int(raw_input("Enter second number"))
Please follow a proper indentation plan with python:
Also, you did not accept the variables while defining your function, and learn how to use print
:
def multiplication(x, y):
m = x * y
print "Multiplication result: %d" % m
Finally, to call this function, use:
multiplication(x, y)
x=int(raw_input("enter first number"))
os=raw_input("Enter the sign of what you wanna do +,-,/,*")
y=int(raw_input("enter second number"))
You can also do like this if you want to keep it in functions.
def input_function():
x = int(raw_input("Enter first number"))
y = int(raw_input("Enter second number"))
return x,y
def multiplication():
x,y = input_function()
m = x * y
print "Multiplication result", m
multiplication()
Or like this, in one function. But it doesn't look so pretty.
def multiplication(x,y):
m = x * y
print "Multiplication result",m
multiplication(int(raw_input('Enter first number')),int(raw_input('Enter second number')))
def r():
v = int(input("voltage: "))
i = int(input("current: "))
resistance = v*i
return(resistance,'ohms')