Python Forum
Struggling with variables
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Struggling with variables
#1
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)
Reply
#2
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
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling on Tuples Mystix 3 4,926 Feb-01-2021, 06:06 PM
Last Post: nilamo
  Struggling To Understand These 2 Python Files samlee916 2 1,804 Sep-22-2020, 04:50 AM
Last Post: ndc85430
  struggling w/ fonctions in Python Tiril123 7 3,888 May-09-2020, 10:51 AM
Last Post: pyzyx3qwerty
  struggling with one part of python Lucifer 23 6,900 May-08-2020, 12:24 PM
Last Post: pyzyx3qwerty
  struggling with python save/load function newatpython00 1 2,018 Nov-15-2019, 07:58 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020