[pythonvis] Re: Trace back error

  • From: "Joseph Lee" <joseph.lee22590@xxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Thu, 22 May 2014 15:44:54 -0700

Hi Al,

To add to Richard’s comment, the specific error is your print statement: I 
think you meant to print the value stored in eventCount, not eventcount which 
wasn’t declared at all.

Cheers,

Joseph

From: pythonvis-bounce@xxxxxxxxxxxxx [mailto:pythonvis-bounce@xxxxxxxxxxxxx] On 
Behalf Of Richard Dinger
Sent: Thursday, May 22, 2014 3:41 PM
To: pythonvis@xxxxxxxxxxxxx
Subject: [pythonvis] Re: Trace back error

 

You have evencount not evenCount in your print statement.  Python is case 
sensitive.

 

Richard

From: Al B <mailto:ablazik@xxxxxxxxxxx>  

Sent: Thursday, May 22, 2014 1:13 PM

To: pythonvis@xxxxxxxxxxxxx 

Subject: [pythonvis] Trace back error

 

Hi Listers,

I created a separate program for the first sample loop program from Joseph and 
ran it. The answer displayed was 53. Not accepting this answer, I attempted to 
modify my program to print out each loops data fields: the number being 
examined and the counter value of even numbers. When that program was run, it 
produced a trace back error which said that "evencount is not defined.

Would someone tell me what I did wrong? Program code is below.

 

TIA, Al B

 

# sample loop program from Joseph

import random

random.seed()

l = []

for i in range(0, 100): l.append(random.randint(0, 100))

evenCount = 0

for numbers in l:

if numbers%2 == 0: evenCount+=1

print numbers%2 , evencount

print evenCount

 

# The following statement halts the program 

# so you can look at the screen

raw_input("press Enter to end program")

 

 

 

 

Other related posts: