0
Can someone tell me why my code is working for only one input. if try to run it second time by typing yes then it prints none
6 Antworten
+ 1
#Return the function
list={}
def mine():
a1=input('enter your variable:-')
print()
a2=input('enter its value:-')
print ()
list[a1]=a2
a3=(input('Do you want to enter any new variable:-')).lower()
print()
if a3=='yes':
return mine() # added return
elif a3=='no':
a4=list
return a4
print(mine())
https://code.sololearn.com/cwe7v5vjVw3n/?ref=app
+ 1
You should enter all input at once
Like this👇
X
4
yes
Y
5
no
+ 1
Thanks Steven and jayakrishna.
You both are correct but I like Steven's answer
+ 1
Krishna Agrawal,
If possible, try not to use type name as variable name. `list` is a type name, and thus it would be inappropriate being used as variable name, may cause confusion or unexpected behaviour 👍
0
list={}
def mine():
a1=input('enter your variable:-')
print()
a2=input('enter its value:-')
print ()
list[a1]=a2
a3=(input('Do you want to enter any new variable:-')).lower()
print()
if a3=='yes':
mine()
return list
#No need else, return from else goes last call of mine() and first call to mine() then retuning nothing..
print(mine())
0
Thanks bro for your suggestion. But I know it. And it is just a sample part of a big program and I tried to make it as simple as possible