I guess I don't get for in range statements

I’m new to programming in Python (years ago, I was pretty OK programming in C). I recently wrote my first program for the EYESY (Basic Circle | Patchstorage). However, I’m now working on my second patch for the EYESY. This one contains a for in range statement. A test version of the code without the for in range statement works fine . . .

import os
import pygame
import time
import random
import math

def setup(screen, etc):
    pass

def draw(screen, etc):
	color = etc.color_picker(etc.knob4)
	linewidth = int (1+ (etc.knob3)*10)
 	etc.color_picker_bg(etc.knob5)  

	x2 = int (abs (etc.audio_in[0])/25)
        y2 = int (abs (etc.audio_in[0])/50)
        x3 = int (abs (etc.audio_in[1])/25)
        y3 = int (abs (etc.audio_in[1])/50)
	pygame.draw.line(screen, (color), [x2,y2], [x3, y3], linewidth)

However, when I add the for in range statement, the EYESY won’t execute the code . . .

import os
import pygame
import time
import random
import math

def setup(screen, etc):
    pass

def draw(screen, etc):
	color = etc.color_picker(etc.knob4)
	linewidth = int (1+ (etc.knob3)*10)
 	etc.color_picker_bg(etc.knob5)  

for i in range(0, 99):
	x2 = int (abs (etc.audio_in[i])/25)
        y2 = int (abs (etc.audio_in[i])/50)
        x3 = int (abs (etc.audio_in[(i+1)])/25)
        y3 = int (abs (etc.audio_in[(i+1)])/50)
	pygame.draw.line(screen, (color), [x2,y2], [x3, y3], linewidth)

Any ideas of what I’m doing wrong?

Thanks:

Jim

Make sure the indentation is correct (important in Python, not like C). It should look like this:

def draw(screen, etc):
    color = etc.color_picker(etc.knob4)
    linewidth = int (1+ (etc.knob3)*10)
    etc.color_picker_bg(etc.knob5) 

    for i in range(0, 99):
        x2 = int (abs (etc.audio_in[i])/25)
        y2 = int (abs (etc.audio_in[i])/50)
        x3 = int (abs (etc.audio_in[(i+1)])/25)
        y3 = int (abs (etc.audio_in[(i+1)])/50)
        pygame.draw.line(screen, (color), [x2,y2], [x3, y3], linewidth)

Also, are you able to see an error in the web editor, it should give some idea (are you using the web editor ?)

1 Like

Thanks so much!