This is a restriction. You force me to provide the input in the CLI, and the function provides the result on the CLI
def say_hello():
name = input('enter a name: ')
print('hello ' + name)
# call the function
say_hello()
This is not only for python, this paractice is good for all programming language
# best practice (input and output are outside the function)
def add(x, y):
return x + y
print(add(3, 4)) # call and print result
print(add(2, 7)) # call and print result
result = add(10, 3) # call store results in a variable
result += 3 # flexibility
print(result)
# best practice (input and output are outside the function)
def say_hello(name):
msg = 'hello ' + name
msg += '\nwelcome to python II'
return msg
print(say_hello('Ahmed'))
name1 = input('enter a name: ')
result = say_hello(name1)
result += '\npython is cool'
print(result)