DogeTheDoggo
Badges: 16
Rep:
?
#1
Report Thread starter 1 month ago
#1
I'm a beginner at python and I am currently solving some Euler problems to learn.
Could someone please take a look at this code and see why its not working ?

https://github.com/DogeTheDogg/Euler-Problems.git

The output doesn't show for some reason.
0
reply
0le
Badges: 21
Rep:
?
#2
Report 1 month ago
#2
I would need to see the question but the output does not show probably because the program never reads that part of the code. Can you post what the question was?
0
reply
DogeTheDoggo
Badges: 16
Rep:
?
#3
Report Thread starter 1 month ago
#3
(Original post by 0le)
I would need to see the question but the output does not show probably because the program never reads that part of the code. Can you post what the question was?
https://projecteuler.net/problem=5
0
reply
0le
Badges: 21
Rep:
?
#4
Report 1 month ago
#4
I thought that would help me help you but it did not .

I have run the code in my terminal and it does provide an output, although the WHILE loop runs endlessly.
0
reply
mqb2766
Badges: 19
Rep:
?
#5
Report 1 month ago
#5
(Original post by 0le)
I thought that would help me help you but it did not .

I have run the code in my terminal and it does provide an output, although the WHILE loop runs endlessly.
Agree, the break jumps out of the inner (for) loop only. Not the infinite while loop as the first elif is never reached.

The OP always breaks out of the for loop for the first x (=2). Its either not a factor (if) or a factor and < num (second elif). Chucking it through a debugger would make this clear
Last edited by mqb2766; 1 month ago
0
reply
DogeTheDoggo
Badges: 16
Rep:
?
#6
Report Thread starter 1 month ago
#6
After re-reading the code, I've realised the mistake.
I would break the loop even when y %x == 0 thus not allowing the other numbers in the range be to tested.

I rewrote the code so if anybody could check that out.

https://github.com/DogeTheDogg/Euler-Problems
0
reply
mqb2766
Badges: 19
Rep:
?
#7
Report 1 month ago
#7
(Original post by DogeTheDoggo)
After re-reading the code, I've realised the mistake.
I would break the loop even when y %x == 0 thus not allowing the other numbers in the range be to tested.

I rewrote the code so if anybody could check that out.

https://github.com/DogeTheDogg/Euler-Problems
having a look now, but have you tried some test cases? one is given in the question.

Looks ok?

note there are a few imporovements, like can you remove the 2nd elif completely, casting the number when you read it in, starting y at num, processcontinue?, the first part of the first elif test is redundant, increment y by 2, put the print after the loop is good practice ... Also the question is askking for the lowest common multiple of the set of numbers and there are a variety of ways you could approach it.
Last edited by mqb2766; 1 month ago
0
reply
DogeTheDoggo
Badges: 16
Rep:
?
#8
Report Thread starter 1 month ago
#8
(Original post by mqb2766)
having a look now, but have you tried some test cases? one is given in the question.

Looks ok - can you remove the 2nd elif completely?

note there are a few imporovements, like casting the number when you read it in, starting y at num, processcontinue? ... Also the question is askking
for the lowest common multiple of the set of numbers and there is a variety of ways you could approach it.
I did try a few test cases. Its working alright I think.
It worked even when I removed the 2nd elif

Alright, so I've converted num into an int at the beginning itself.
process_continue was another variable I had made that I forgot to delete

Should I explore more ways to solve the problem then ?
0
reply
mqb2766
Badges: 19
Rep:
?
#9
Report 1 month ago
#9
(Original post by DogeTheDoggo)
I did try a few test cases. Its working alright I think.
It worked even when I removed the 2nd elif

Alright, so I've converted num into an int at the beginning itself.
process_continue was another variable I had made that I forgot to delete

Should I explore more ways to solve the problem then ?
I was editing the improvements as you replied, so there are a couple more in the previous post.
Solving a problem several different ways is generally good practice. Time it/put a large number in to compare efficiency and algorithm design.
Last edited by mqb2766; 1 month ago
0
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

Personalise

Do you think receiving Teacher Assessed Grades will impact your future?

I'm worried it will negatively impact me getting into university/college (139)
42.77%
I'm worried that I’m not academically prepared for the next stage in my educational journey (38)
11.69%
I'm worried it will impact my future career (27)
8.31%
I'm worried that my grades will be seen as ‘lesser’ because I didn’t take exams (68)
20.92%
I don’t think that receiving these grades will impact my future (34)
10.46%
I think that receiving these grades will affect me in another way (let us know in the discussion!) (19)
5.85%

Watched Threads

View All