0
Set default in a module
I'm making my own module now to help me in my programs.How Can I set a default in a function of it that has more than one parameter,as if the user doesn't enter one parameter of them,The parameter will be a default I set.
17 Answers
+ 2
No bro you had asked for default parameter
repeat=input("to try again press enter") or another_parameter
So instead of another parameter you may use any value when no value will go from input command then it will automatically use the given parameter after the or logical statement.
+ 2
👍👍😊
+ 2
Your above code is not matching with this code. You may come to personal chat with me to avoid long conversations here.
+ 2
i think the way to do that is to declare the default when you create the function inputs ie
def function(input1, input2=“mydefault”):
this cause input2 to default to “mydefault” if left empty.
+ 1
You may use or for this purpose
0
TR CodeWorld [AYUSH.ks]
More explaining please
0
Hay Ahmad Tarek please share your source code with us so that we can help you
0
TR CodeWorld [AYUSH.ks]
def restart(function,parameter):
repeat = input("To try again press Enter")
if repeat == "":
function(parameter)
else:
exit()
0
this was the function in the module file
0
repeat=input("to try again press enter") or another_parameter
Use this for your purpose
0
TR CodeWorld [AYUSH.ks]
def restart(function,parameter):
repeat = input("To try again press Enter")
if repeat == "":
function(parameter)
else:
exit()
or
repeat = input("To try again press Enter")
if repeat == "":
function()
else:
exit()
Do you mean that?
0
TR CodeWorld [AYUSH.ks]
Ok man I understand it now
Thanks❤️
0
TR CodeWorld [AYUSH.ks]
def restart(function,parameter):
ss = parameter or ()
repeat = input("To try again press Enter")
print("")
if repeat == "":
function(ss)
else:
exit()
is this right?
0
def restart(function,parameter):
repeat = input("To try again press Enter") or parameter
print("")
if repeat == "":
function(ss)
else:
exit()
0
still giving me this error
TypeError: restart() missing 1 required positional argument: 'parameter'
0
Please share your code
0
import jkhk
def das():
print(12+5)
jkhk.restart(das)
das()