![]() |
Struggling with variables - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Struggling with variables (/thread-29855.html) |
Struggling with variables - pythonstudy00 - Sep-23-2020 Hey I am studying Python new to it and trying to write a program short code that checks which numbers divide evenly into 1241... tried this but just cant get the variables right. Also studying algebra beginners. n=0 i = 0 n=0 for i in range(0,1241): if (n%i == 0): print(i,"divides evenly into",n)idk if it needs a counter.. i am so lost Thanks Fixed it now: n=1241 i = 0 for i in range(1,1242): if (n%i) == 0: print(i,"divides evenly into",n) RE: Struggling with variables - DPaul - Sep-23-2020 On the right track. But arguably in line 3: "i" does not need to go all the way to 1241. 1240 will not divide, 1239 neiither ... etc. Until... Paul |