Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Constructive Criticism

Name: xpoferens 2009-03-28 0:47

These tutorials make me do such basic shit, so I decided to do my own thing and copy some built in functions. Here's my first attempt at a range function. From lurking around here I've learnt that there are many ways to do the same thing, and some ways are more efficient than others. Am I doing this the complete noob way? Is there a more efficient way?

def myrange(a, b, c):
    while True:
        if b == 0:
            print('incorrect b value')
            break
        else:
            i = a
            a += b
            if abs(a) > abs(c + b):
                break
            else:
                print(i)
                continue
                print(a)
                       
       
myrange(1, 1, 10)

#Im pretty proud of my work, considering the time I have been programming, but I want to learn to be better, so any constructive criticism is welcome. If you guys want me to stop posting n00b programs tell me and I will stop.

Name: Anonymous 2009-03-28 1:02

In the tutorial one of the functions they showed us looked something like this:

for x in range(1, 1, 10):
    print(x)

*******************
OUTPUT:

1
2
3
4
5
6
7
8
9
*******************

I didnt like the fact that the 10 was not inclusive so I wanted to make my own version of this built in function, so this is what I did. Maybe I am not seeing the bigger picture and that my function wont work the same way as a "for x in range(a, b, c)" loop but thats all i was trying to do.

As for the |a| > |c|, thats the only way i could think of making it stop going printing to infinity. maybe I should have documented that

a is start,

b is step

c is last value (inclusive unlike built in range)

Do you get what I am trying to do?

How would you have done it?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List