1

I have this code below:

def my_function(username,greetings):
    username = input("enter your name:")
    print("Hello %s , I wish you %s"%(username,greetings))

I would expect to be asked for the input when I run it, but it doesn't show the "enter your name:"

depperm
  • 10,606
  • 4
  • 43
  • 67
Stergios
  • 53
  • 3

2 Answers2

0

I believe this is what you're looking for.

def my_function(username, greetings):
    print("Hello %s , I wish you %s"%(username, greetings))

username_input = input("enter your name:")
greetings_input = input("enter your greeting:")
my_function(username_input, greetings_input)

Explanation

def my_function() has the function definition which takes two parameters i.e username and greetings as inputs to the function. The function prints the statement Hello ..., I wish you ... with appropriate replacements

When you run the python code, the line username_input requests the user for an input of the name and the result is stored in the variable. Similarly with greeting_input.

You then have to call the function by using the name of the function i.e. my_function() with the appropriate parameters taken as input. So the function call happens by doing my_function(username_input, greeting_input)

All the best with your learning. Hope this helps

Sudheesh Singanamalla
  • 2,283
  • 3
  • 19
  • 36
0

great work so far, what you're doing wrong, is the username have to be instantiated before passing it as parameter to the function,

# declating the function
def my_function(username,greetings):
    print("Hello %s , I wish you %s"%(username,greetings))

#reading the username from the user input
username = input("enter your name:")

# initiating greetings variable
greetings = 'some greetings'

#calling the function with the previously declared variables
my_function(username, greetings)