What is problem in my code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is problem in my code?

I don't know why my function program doesn't work here in cycle ishora=True while True: son=int(input("Sonni kiriting: ")) def ikkiga_bol(son): """Kiritilgan sonni 2 dan 10 gacha qaysi biriga qoldiqsiz bo'linishini ko'rsatadigan finksiya""" sonlar=list(range(2,11)) for son1 in sonlar: if son%son1==0: print(son1) savol=input("Yana son kiritasizmi? (yes/no)") if savol=='no': ishora=False

20th Jan 2023, 7:20 AM
Shokhrukh Abdivoitov
Shokhrukh Abdivoitov - avatar
4 Answers
+ 2
Shokhrukh Abdivoitov But you are not using that "ishora" Variables anywhere so it's wastage then. Use it to stop loop. And you are not using function also. Instead of defining in the while loop, declare it out side and call it to make use of it. Here is corrected working code: def ikkiga_bol(son): """Kiritilgan sonni 2 dan 10 gacha qaysi biriga qoldiqsiz bo'linishini ko'rsatadigan finksiya""" for son1 in range(2,11): #without list if son%son1==0: print(son1) ishora=True while ishora : # use ishora variable son=int(input("Sonni kiriting: ")) ikkiga_bol(son) # use the function savol=input("Yana son kiritasizmi? (yes/no)") if savol=='no': ishora=False
20th Jan 2023, 8:16 AM
Jayakrishna 🇮🇳
+ 1
Save code in playground and share link here... Indentation matters.. I think it loop, cycles infinite times..
20th Jan 2023, 7:53 AM
Jayakrishna 🇮🇳
0
You have infinite loop now while is always true, you can use some variable set it to true and than inside loop set to false, like ishora variable. Also you define function inside loop, what is wrong, define it outside and call inside.
20th Jan 2023, 7:52 AM
PanicS
PanicS - avatar
0
Here is word "Ishora" is true in the beginning In function it becomes False if you text no
20th Jan 2023, 8:03 AM
Shokhrukh Abdivoitov
Shokhrukh Abdivoitov - avatar