Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 23rd, 2003, 12:35 PM
tricia tricia is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 tricia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
counter does not go forward

Hi!

I cannot understand why the counter in the following does not work. Any ideas? Thanks in advance.

temp = a list of different cases,
eg: temp = [['texta', '234', '345'],['textb', '3453', '43']]

result = the list of numbers found in temp
eg: result = [234, 345, 3453, 43]

Code:
for i in result: 
     d = d + 1 
     sum = result[d]
     output.write(str(result[d]) + ' ')
     s = d
     while s != len(result):
       s = s + len(result)/len(temp)
       sum = sum + result[s]
       output.write(str(result[s]) + ' ')
       output.write(str(sum) + NL)


(my apologies, I don't know why the indentation is messed up)

Last edited by tricia : July 23rd, 2003 at 06:32 PM.

Reply With Quote
  #2  
Old July 23rd, 2003, 12:44 PM
percivall percivall is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 133 percivall User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Use the '#' button to insert code.

Reply With Quote
  #3  
Old July 23rd, 2003, 12:54 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
Send a message via MSN to SolarBear
The way I see it, you did not give any initial value to d. So Python is saying "Yeah, I'm adding 1 to WHAT ?". Python does not even know what type d is if you don't initialize it. Simply add d = 0 at the beginning of your code.

Reply With Quote
  #4  
Old July 23rd, 2003, 12:58 PM
tricia tricia is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 tricia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
my mistake, i forgot to add it. I do have d=0 just before 'for i in result:' but it still won't do it. d just gets stuck to 0.

Reply With Quote
  #5  
Old July 23rd, 2003, 12:59 PM
tricia tricia is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 tricia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
it gets stuck to 1 i meant.

Reply With Quote
  #6  
Old July 23rd, 2003, 01:08 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,537 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 17 m 47 sec
Reputation Power: 68
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Is this a counter script for a web page, as in CGI? Whats it surposed to do? Also this can't be the whole script, can you post the rest please?

Take care,
Mark.

Reply With Quote
  #7  
Old July 23rd, 2003, 06:21 PM
SolarBear's Avatar
SolarBear SolarBear is offline
onCsdfeu
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Canada
Posts: 100 SolarBear User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 21 sec
Reputation Power: 10
Send a message via MSN to SolarBear
This may not be your problem, but why don't you use
Code:
for d in result
? You're creating a counter variable (i) but you're not using it.

And as netytan said, post the whole code.

Reply With Quote
  #8  
Old July 23rd, 2003, 09:21 PM
CottonBuds CottonBuds is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 1 CottonBuds User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hi tricia,

It seems that you're having a bit of confusion in 'nested' loops (probably)

I presume python nested loops works as any other programming language. eg: first the outer loop executed once, then executes the inner until it finishes or finds a condition, the again the outer loop again.... isn't it right?

As I can see from your code you've got a 'for' loop which you you want the var 'd' to increment.

Then you're using a 'while' loop.
and you've alredy told us that 'd' is being initialise somewhere in your code. OK...
let's see now, I think there's something wrong in the while 'loop' condition....

This is what your loop code does:
1. Goes to 'for' then blah blah
2. Goes in the 'while s != len(result):'
presumably: s = d which is 1 and len(result) = 4 or 5 or 6.
Which in this case you need it to be 1 != 4, and the condition is correct!
Then s = s + len(result)/len(temp)
s = 1 + 4/2 equals 3 then while loop check condition 3 != 4 - nop
s = 3 + 4/2 equals 5 then while loop check condition 5 != 4 - nop
s = 5 + 4/2 equals 7 then while loop check condition 7 != 4 - nop
... and this goes forever ....

When you get in 'while' loop the program stay in it, like forever....
how do you get out of there?
Code:
     while s != len(result):
       s = s + len(result)/len(temp)
       sum = sum + result[s]
       output.write(str(result[s]) + ' ')
       output.write(str(sum) + NL)


A solution:
If you can find a way to get out from the while loop. 'd' might be able to increment.

I don't know if I'm right, anyway good luck.


Mina Saiiiii!

Last edited by CottonBuds : July 23rd, 2003 at 09:34 PM.

Reply With Quote
  #9  
Old July 24th, 2003, 08:03 AM
tricia tricia is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 4 tricia User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
here is the full code, hope it helps.

Code:
text = [['txt1-0', '123', '231241', '23'],['txt1-1', '1233','23','413'],['txt2-0','34','3','5']]

def add(text):
  temp = []
  ## read the file name, if the next filename has the same main digit, continue till you find sth different
  ## if not, go back and add the numbers as if in columns, and create a new entry.
  ## eg. text = [['txt1', '1356', '231264', '436],['txt2','34','3','5']]
  a = -1; first = a + 1
  for i in text:
    a = a + 1
    try:
      if text[a+1][0][3] == text[first][0][3]:
        temp.append(i)
      else:
        b = -1; result = []
        for i in temp: ## gather all the scores in one list
          b = b + 1; c = -1
          for s in i[1:]:
            c = c + 1
            result = result + [float(temp[b][1:][c])]
            d = -1; sum = 0
            for i in result: 
              d = d + 1 
              sum = result[d]
              s = d
              while s != len(result):
                s = s + len(result)/len(temp)
                sum = sum + result[s]
    except IndexError: pass    


there should be more but i haven't written it yet.

Last edited by tricia : July 24th, 2003 at 08:08 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > counter does not go forward

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap