Pranav K S
Pranav K S

Reputation: 11

what should i do now to solve the issue because it is showing x is not defined?

def fun2(x):
    return 2*x
a = fun2(x)
print(a)

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-16-ea6b97e2013c> in <module>
      1 def fun2(x):
      2     return 2*x
----> 3 a = fun2(x)
      4 print(a)

NameError: name 'x' is not defined

Upvotes: 0

Views: 37

Answers (3)

karel
karel

Reputation: 5851

Pass a value to x by asking the user to enter a number, which will be assigned to variable x. float converts the input number from a string to a floating point number.

x = float(input("Enter a number: ")) # Enter a value for x.
def fun2(x):
    return 2*x
a = fun2(x)
print(a)

Upvotes: 0

mukesh palsaniya
mukesh palsaniya

Reputation: 11

You have passed function parameter as x in 3rd line. Either set x before passing argument or You should pass a number in third line like : a=fun2(4)

Upvotes: 0

Ugur
Ugur

Reputation: 2024

You did not pass a value to x. That‘s why.

When you call your function, you need to pass a value to it, for instance: 5.

a = fun2(5)

Upvotes: 1

Related Questions