'Spam' and 'Eggs' (the list) [solved]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lostbuttrying
    New Member
    • Nov 2006
    • 10

    'Spam' and 'Eggs' (the list) [solved]

    I need to generate a list containing 500 words. Each word should be, 'Spam', unless the index of the word in the list is a multiple of 3 or 5. In which case the word should be, 'eggs'. The index of the first word is 0.

    Anyone know where I should start?
    Thanks in advance for the help.
  • Subsciber123
    New Member
    • Nov 2006
    • 87

    #2
    Your question is not clear enough. State an EGGsample of what you want to start with, and what you want to end with.

    Comment

    • lostbuttrying
      New Member
      • Nov 2006
      • 10

      #3
      Sorry...I wrote the question exactly as my homework ask it. Maybe thats why I feel lost:

      I guess I should have a list ['eggs', 'Spam', 'Spam', 'eggs', 'Sam', 'eggs', 'eggs', 'Spam', 'Spam', 'eggs', 'eggs', 'Spam', 'eggs', 'Spam', 'Spam', 'eggs', 'spam',.......]
      but I need to find out how to write that I want the multiples of 3 and 5 to say eggs and all the rest to say Spam.

      Hope that is clearer........

      Comment

      • Subsciber123
        New Member
        • Nov 2006
        • 87

        #4
        Code:
        my_list=["spam"]*500
        for i in range(500):
            if i%3==0 or i%5==0:
                my_list[i]="eggs"
        print my_list
        That should just about do it.

        Comment

        • lostbuttrying
          New Member
          • Nov 2006
          • 10

          #5
          Thank you so much! I have been working on that question for the last 2 hours. Your response works perfect!
          I really appreciate the help!!!!
          = )

          Comment

          Working...