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.

19th Apr 2020, 2:36 PM
Ahmad Tarek
Ahmad Tarek - avatar
17 ответов
+ 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.
19th Apr 2020, 3:34 PM
Ayush Kumar
Ayush Kumar - avatar
+ 2
👍👍😊
19th Apr 2020, 3:39 PM
Ayush Kumar
Ayush Kumar - avatar
+ 2
Your above code is not matching with this code. You may come to personal chat with me to avoid long conversations here.
19th Apr 2020, 5:18 PM
Ayush Kumar
Ayush Kumar - avatar
+ 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.
20th Apr 2020, 9:20 PM
madeline
madeline - avatar
+ 1
You may use or for this purpose
19th Apr 2020, 2:41 PM
Ayush Kumar
Ayush Kumar - avatar
0
TR CodeWorld [AYUSH.ks] More explaining please
19th Apr 2020, 2:47 PM
Ahmad Tarek
Ahmad Tarek - avatar
0
Hay Ahmad Tarek please share your source code with us so that we can help you
19th Apr 2020, 3:00 PM
Ayush Kumar
Ayush Kumar - avatar
0
TR CodeWorld [AYUSH.ks] def restart(function,parameter): repeat = input("To try again press Enter") if repeat == "": function(parameter) else: exit()
19th Apr 2020, 3:11 PM
Ahmad Tarek
Ahmad Tarek - avatar
0
this was the function in the module file
19th Apr 2020, 3:11 PM
Ahmad Tarek
Ahmad Tarek - avatar
0
repeat=input("to try again press enter") or another_parameter Use this for your purpose
19th Apr 2020, 3:14 PM
Ayush Kumar
Ayush Kumar - avatar
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?
19th Apr 2020, 3:28 PM
Ahmad Tarek
Ahmad Tarek - avatar
0
TR CodeWorld [AYUSH.ks] Ok man I understand it now Thanks❤️
19th Apr 2020, 3:37 PM
Ahmad Tarek
Ahmad Tarek - avatar
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?
19th Apr 2020, 4:41 PM
Ahmad Tarek
Ahmad Tarek - avatar
0
def restart(function,parameter): repeat = input("To try again press Enter") or parameter print("") if repeat == "": function(ss) else: exit()
19th Apr 2020, 5:05 PM
Ayush Kumar
Ayush Kumar - avatar
0
still giving me this error TypeError: restart() missing 1 required positional argument: 'parameter'
19th Apr 2020, 5:11 PM
Ahmad Tarek
Ahmad Tarek - avatar
0
Please share your code
19th Apr 2020, 5:12 PM
Ayush Kumar
Ayush Kumar - avatar
0
import jkhk def das(): print(12+5) jkhk.restart(das) das()
19th Apr 2020, 5:16 PM
Ahmad Tarek
Ahmad Tarek - avatar