I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
I mean, you can’t? You are telling Python to make a loop and execute that print-command.
If you want Python to do something different in the last loop, you need either shorten the loop and have the last entry executed after the loop OR design the loop with a counter, get the actual length of the loop and an if-statement to execute different code in the final loop.
myval = 1000;
for i in range(myval):
if(i == myval -1):
#something
Messing around with a Python emulator, after fixing some typos…
The end keyword replaces the NL at the end of the line, without that, the line won’t print. Maybe there is a more elegant way, but if I stick print('') at the end of your program, it tags on a NL so it finally prints that line.
It just prints out the problems accordingly without space in between
But what i actually want is 4 spaces between each problem according to the task…
So, i’m trying to loop through the ‘numerator’ and ‘denominator’ variable and add 4 spaces(i.e ’ ')between them and then print everything out
I want my numerator and denominator to finally look like this
In this case, you are not supposed to print values, but to create a string and then return that.
While you still cannot easily get the last loop, you can just slice off the end of the string or use some strip-method if it’s only spaces.