1

I'm just starting out with Python.I'm making a basic calculator. When I input a number ,I have to do it like this :

Number= int(input("Enter your number"))

And I was thinking if I could make a function ,like this:

def inputting (Number):
Number= int(input("Enter your number")

And then call it whenever inputting.But I have to define a variable before I use it in a function,and that can only be done by assigning a value. And instead of the value entered , it takes the value previously assigned when I use it later.

def inputting (Number):
Number= int(input("Enter your number")

FirstNum= none
inputting(FirstNum)
print (FirstNum)

and instead of printing the value I'd typed in there, it just prints none How do I make this work?

Satvik Gupta
  • 53
  • 1
  • 2
  • 7
  • As ŁukaszRogalski's link shows, Python doesn't work like that, so just assign `FirstNum` to the value returned by your `inputting` function. (BTW, CamelCase names are generally reserved for Class names in Python, for simple variables & functions, use snake_case names, eg first_num). You should also take a look at http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response – PM 2Ring Aug 15 '16 at 11:32

1 Answers1

2

You need to use return:

def inputting(my_number):
    return int(my_number)

Or:

def inputting():
    return int(input("Enter your number"))

my_number = inputting()
Idos
  • 15,053
  • 14
  • 60
  • 75