Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (anonymous):

Loop – Your program will print a sequence of numbers, where the last number is the current loop iteration. For example, if you are on loop iteration number 5, your program will print the following. 1 2 3 4 5

OpenStudy (anonymous):

My program uses a while loop. I am thinking and looping for examples. Please, help if you can. I am using Python!!

OpenStudy (anonymous):

Implement a function loop(N) that you call to print the sequence of numbers.

OpenStudy (anonymous):

@thomaster hi there, anyway you could give me some guidance here?

OpenStudy (kva1992):

for i in range(5): print(i) that should be the code if im not mistaken

OpenStudy (rsmith6559):

Just for fun, try: r = range( 5 ) print r

OpenStudy (anonymous):

The range shouldn't be limited. def main(): counter=1 while True: counter=counter+1 I need to get the counter value into a function. So, when I call the function it prints the iteration. What I actually need is different. I need it to print a list; but, simply getting this to run would make feel much better.

OpenStudy (woodrow73):

So add a function call to output the numbers 1-currentNum inside your loop?

OpenStudy (woodrow73):

@AlexADB

OpenStudy (anonymous):

@woodrow73 sorry for the delay. i was trying to figure this out and didn't think anyone would respond. I'm struggling writing the code for that output. I'm over thinking this. I know it wouldn't be more than like 2-3 lines or code.

OpenStudy (anonymous):

@woodrow73 could you guide me through writing this output. i don't expect you to give me an answer. i'm just not understanding some things and i've been running into a wall since yesterday.

OpenStudy (woodrow73):

I'm no python guy, but I'll give it a shot; googling/duckduckgo-ing for syntax examples is very helpful

OpenStudy (anonymous):

@woodrow73 okay, i'll try that. and i'll keep checking back here every few minutes. thank you very much.

OpenStudy (green_1):

what version of python are you talking about?

OpenStudy (anonymous):

@green_1 i'm using 3.5

OpenStudy (woodrow73):

No worries. It's a pretty good approach to first lay out the logic / pseudocode, and then to piece it together with the syntax. For this problem, we basically want 1. to keep looping forever, with a variable x increasing by 1 each iteration (loop cycle) 2. each loop, we need to call a function that will print 1-x inclusive 3. after the function call, add 1 to x ``` def func(q): z = 1 for z in range(1, q+1): print z x = 1 for x in range(0, 101):#or while True: func(x) x=x+1 print '-------------------' ```

OpenStudy (green_1):

have you tried applying base 64 and useing syntax decode on script 3

OpenStudy (woodrow73):

Appears that you don't need to change x's value within the in range code, since it automatically changes x's value. Though the manual increment change will still help in the while True:

OpenStudy (rsmith6559):

Quick and dirty in the shell: >>> def count( x ): ... i = 1 ... while( i <= x ): ... print( i ) ... i += 1 ... >>> count( 5 )

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!