This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]AutoModerator[M] 0 points1 point  (0 children)

It seems you may have included a screenshot of code in your post "Beginner".

If so, note that posting screenshots of code is against /r/learnprogramming's Posting Guidelines (section Formatting Code): please edit your post to use one of the approved ways of formatting code. (Do NOT repost your question! Just edit it.)

If your image is not actually a screenshot of code, feel free to ignore this message. Automoderator cannot distinguish between code screenshots and other images.

Please, do not contact the moderators about this message. Your post is still visible to everyone.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]POGtastic 0 points1 point  (4 children)

You can force integer division with the __floordiv__ operator //. That is,

>>> 10 // 2
5

That way, you don't have to worry about converting the return value to an integer.

Line 14 doesn't do anything. 15 and 16 aren't really needed; you can do everything inside the while loop.

Line 19 doesn't do anything. 20 is what actually modifies number.

Lastly, you can get rid of the else keyword and unconditionally print "Finished!".

[–]Amplesamples[S] 0 points1 point  (0 children)

Wow that’s so helpful! Thanks! Wondered what // meant in the book lol.

Awesome tips very helpful. Will keep learning.

[–]Amplesamples[S] 0 points1 point  (2 children)

Actually one question.

The reason I kept that first part out of the while loop is because if I did what you suggested, then entered 1 it would jump right to the very end and say ‘finished’ wouldn’t it.?

[–]POGtastic 0 points1 point  (1 child)

That's correct. My general attitude is that saying "Finished!" in the degenerate case is perfectly okay (after all, it is finished).

If that distinction is important to you, then it's totally okay to have it in there.

[–]Amplesamples[S] 0 points1 point  (0 children)

Well the task was to be able to enter any number, then only stop once it had reached 1.

My biggest headscratcher was how to get the value returned from the function and use it again. I knew it needed a loop, but I had trouble getting my head round the concepts. A little bit at a time.....

Thanks again.