I am trying to create a function that accepts a variable, and optionally a data type and a prompt as arguments, then calls input() and assigns the input to the variable in the arguments.
def inp(var, prompt='', intype=str):
var = intype(input(prompt))
return None
Now, if I do this (assuming name x is already defined):
inp(x,'hello',int)
I want to print "hello" (that part already works) then convert the input received into an int and store it in variable x.
However, it does not seem to work. (the required value is not assigned to the variable passed as argument). I am aware that my code is awkward, so how can I make it work?