Latest Awards
Complete 10 python programs which focus on loops.

morgan

Score over 100 points in total

vincebanter10

Complete any 5 python programs

vincebanter10

Complete 3 python list based tasks

vincebanter10

Complete 5 python list based tasks

vincebanter10

Complete 10 python list based tasks

dman12

Score over 1000 points in total

april-logan

Complete any pygame task

april-logan

Complete any 3 pygame tasks

april-logan

You have to complete 5 pygame tasks

april-logan

Score over 500 points in total

sam-edmund

Complete any pygame task

sam-edmund

Complete any 3 pygame tasks

sam-edmund

You have to complete 5 pygame tasks

sam-edmund

Complete any pygame task

12wrigleyf

Complete any 3 pygame tasks

12wrigleyf

You have to complete 5 pygame tasks

12wrigleyf

Score over 500 points in total

jhoughton12

Complete any 10 python prograns

jhoughton12

Complete 10 python programs which focus on loops.

jhoughton12

Python Score
tasks = 0
achivements = 0
freestyle = 0
Total = 0
Top 5 Scores
114gilo 3500
2joss-nolan-2 2530
3alexdawkins 2515
4byrnebrian 2080
512wattsl 1750
Click to view all scores
Who else completed this task?
No one has completed this task yet. Be the first!

Help the cool guys

cool_people = "bert sally susan fred fiona"
pos = 0
start_pos = 0
while pos < len(cool_people):
     if cool_people[pos] == " ":
          print cool_people[start_pos:pos], "is cool"
          start_pos = pos+1
     pos = pos + 1

Not sure what the code does? Well here is an explanation!

line 1 - This creates the list of names, each separated by a space. This is important as we are looking for spaces to separate the names!
line 2 + 3 - This creates two variables and sets them to zero. Pos will keep track of where in the string we are and start_pos will keep track of the start of the name we are currently looking at.
line 4 - Will loop over every letter until we reach the end of the string. We can find the length by using the len function.
line 5 - cool_people[pos] will show the current letter. If this letter is a space then we MUST be at the first character after a name. As such we have just seen every letter of a name.
line 6 - cool_people[start_pos:pos] will return the name. start_pos will point to the start of the name and pos is the current position.
line 7 - This sets the start_pos to be the start of the next name. We add one otherwise we will start the name with a space (remember we are currently looking at a space at this point)
line 8 - Move onto the next letter until there are no more letters left.

In order to miss out the first letter of each name we simply change line 6 to say start_pos+1 when we get the name. Easy? Try it out!

Back to the problem armed with the answer!

Output: (clear)

Leave a Reply

You must be logged in to post a comment.