15. Couting as you go


#1

I need help, badly! Here's my code!

choices = ['pizza', 'pasta', 'salad', 'nachos']

print 'Your choices are:'
for index, item in enumerate(choices):
print "{0} ==> {1}".format(index,item)
print "[{theIndex}] ==> [{theItem}]".format(theIndex=index/ theItem=item)

Please help!


#2

PLEASE, I am EXTREMELY DESPERATE!!
RESPOND QUICKLY PLEASE


#3

If you want to improve your chances of a response and reduce the time until that happens, then make sure that you've got a well stated question and that you have clearly described the situation. Telling people to hurry up is just going to annoy those who might otherwise be willing to help.


#4

This code looks strange. What exactly are you trying to achieve?


#5

this work:

choices = ['pizza', 'pasta', 'salad', 'nachos']

print 'Your choices are:'
for index, item in enumerate(choices, start=1):
    print index, item

#6

Please consider helping your fellow learners, a given answer is just copying and no one will learn from this.


#7

Never, ever go desperately asking for answers without checking the hint. Exercise is easy if you just take a look at the hint.

Code given is this:

choices = ['pizza', 'pasta', 'salad', 'nachos']

print 'Your choices are:'
for index, item in enumerate(choices):
    print index, item

Hint says: Instead of just printing index, print index+1!

And all you have to do is add a +1 next to index. Final code should look a bit like this:

choices = ['pizza', 'pasta', 'salad', 'nachos']

print 'Your choices are:'
for index, item in enumerate(choices):
    print index + 1, item

#8

I completely disagree, by seeing the correct code the user can compare their code to the correct code to view where they went wrong


#9

Sure, but it will also encourage others to just copy and paste. Also, if the errors are serious mistakes, the user might not be able to figure out the mistakes they did just by looking at a code. If your mistake is not a simple accidental typo or something minor, but a logical error, or a mistake that indicates you don't fully understand the philosophy of the answer, looking at the correct code will not help you fully comprehend the point of the exercise. I prefer adding a little text or comment to help people asking questions.


#10

@digitalrunner57215 @cursed1701

Also had a question on exercise 15:

There appears to be two variables following the "for", in this case: "index" and "item". What is happening here - what am I saying to python when I put multiple variables in a for loop? Is there a limit to how many variables you can create in a for loop?

I.e., My understanding is for i in list1 means "for each item i in list1..." - what does it mean now that there are two variables?

Thanks