Hello guest, if you read this it means you are not registered. Click here to register in a few simple steps, you will enjoy all features of our Forum.
Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why isn't this code working ? (noob here)
#1
It should output the list with the dictionary with the changed values as specified in the second for loop, but it doesnt. Picture of output is included.


 aliens = []
for l in range (1,30):
    alien_specs = {'speed':'high' , 'color':'blue' , 'points': 5 }
    aliens.append(alien_specs)

for pi in aliens[:2]:
    if alien_specs['points'] == 5:
        alien_specs['speed'] = 'low'
        alien_specs['color'] = 'red'

for j in aliens[:5]:
    print(j)

print('.............................................')
Im using python 3
Quote
#2
for pi in aliens[:2]:
    if pi['points'] == 5:
        pi['speed'] = 'low'
        pi['color'] = 'red'
99 percent of computer problems exists between chair and keyboard.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  working code, suggestion required for improvement anna 18 238 Dec-29-2017, 01:24 PM
Last Post: buran
  something going wrong.. code is not working anna 9 127 Dec-28-2017, 08:45 AM
Last Post: anna
  Checkbutton code not working ToddRyler 4 104 Dec-24-2017, 12:34 AM
Last Post: Larz60+
  code is not working gullidog 3 145 Nov-09-2017, 09:45 PM
Last Post: Larz60+
  I'm working onn below code to extract data from excel using python kiran 1 197 Oct-24-2017, 01:42 PM
Last Post: kiran
  Please help - Code was working! bm0899 3 349 Sep-15-2017, 07:43 AM
Last Post: buran
  Noob - What attributes to use for agents in evo sim (GA type) PySam 4 353 Sep-13-2017, 07:53 PM
Last Post: PySam
  Noob needs help with code WheeljackG1 0 137 Sep-05-2017, 06:48 PM
Last Post: WheeljackG1
  Why isn't this code working? Hussein26 3 234 Aug-30-2017, 05:51 PM
Last Post: Larz60+
  Code isn't working in several IDE's when other people are getting desired output. SuperSymmetry 1 189 Jul-22-2017, 07:03 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)