Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Back to loops question
#2
You pretty much have it, you just need to save the up/down/sames until the end. What I would do is start with an empty list. Each time you are print a word, append it to the list instead:

>>> count = [1, 2]
>>> count.append(5)
>>> count
[1, 2, 5]
Then you need to print the words. You could just loop through them, printing each one with end = ' ', or you could join them and print once:

>>> ' '.join(['spam', 'spam', 'eggs'])
'spam spam eggs'


I would also change your if's for same and up to elif (short for else if). Then they will only be checked if none of the previous conditions have been met. This is more efficient, and is necessary if you conditions overlap and you only want one to execute.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Back to loops question - by wernerwendy - Jun-17-2017, 09:40 PM
RE: Back to loops question - by ichabod801 - Jun-17-2017, 10:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Old brain - New Language - Question on loops sailingbikeruk 6 5,597 Oct-03-2018, 08:27 PM
Last Post: nilamo
  Question on runtime and improving nested for loops ackmondual 1 3,759 Jun-13-2017, 11:11 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