anonymous
  • anonymous
problem set 1: polpak suggested i write a program that prints integers from 1 to 100. i wrote one that computes up to the value 100 through an iterative loop but i don't know how to actually print each integer from 1 through 100. here's a link to the program. http://dpaste.com/490649/ how do i print the list of integers?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
replying to my own post here! i just saw that polpak suggested i simply count to 100. which this program accomplished. . .
anonymous
  • anonymous
True. Ok, so now make it print each in turn.
anonymous
  • anonymous
i don't know how to do that. eek! i hate asking for you to do this for me but i am unfamiliar with how to print each value.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
that's ok. Let me ask you this, what would happen if you removed line 5 from the program?
anonymous
  • anonymous
not sure. . .i'll go remove it and see what happens.
anonymous
  • anonymous
also, while you're doing that. Print out the value of itersLeft before and after the loop
anonymous
  • anonymous
when i remove y=y+x, the print value returned is simply 1. if I print itersLeft before the loop, I get 99. if i print it after, i get 0.
anonymous
  • anonymous
Ok, so itersLeft is 99 before you execute the loop so we can actually remove the y and the x variables entirely and just say itersLeft = 99. That might make things more clear. Now what happens when you print itersLeft inside the loop?
anonymous
  • anonymous
hmmm. i put the statement 'print itersLeft' in the iterative statement and nothing happened.
anonymous
  • anonymous
dpaste your current version of the code and I'll try to figure out what the problem is. It should certainly have done something.
anonymous
  • anonymous
i just redid it. something had gone wrong the first time with my spacing. this time i got a list with values from 98 down to 0. i'm going to increase my itersLeft to 102-x and see what comes back.
anonymous
  • anonymous
wait. You should have removed x and y. You only need to have itersLeft. The x and y variables were specific to the problem trying to be solved in the lecture. For standard iteration you only need 1 counter variable (or some other boolean condition) Just set itersLeft = 99 and see what happens without the x and y
anonymous
  • anonymous
am i just removing y=y+x or am i completely removing y from the program?
anonymous
  • anonymous
you don't need x or y at all. Where you initialize the itersLeft variable, you can just set it directly to 99 (the result of 100-x when x is 1)
anonymous
  • anonymous
alright. now i've gotten a list from 99 to 0. here's the program: http://dpaste.com/490719/
anonymous
  • anonymous
You don't need the x. It's not doing anything useful. See http://dpaste.com/490708/
anonymous
  • anonymous
ah! makes sense. being so new to this, i still don't understand a lot of what i'm doing. so, i'm parroting what i see in lecture until the comprehension sets in!
anonymous
  • anonymous
no problem. I just wanted to simplify the example so you have an easier time understanding how it works. Now, you said that you had a list of numbers from 99 to 0. Techically your version goes from 98 to 0, while mine goes from 99 to 1. See if you can modify my version so that it only goes from 9 to 1.
anonymous
  • anonymous
Also I wanted to clarify something you said. This code does not 'give' a list of numbers. To be correct we can simply say that it will loop 99 times. Each time it loops it will print one number (the current number stored in itersLeft) then change the current number to be the next number.
anonymous
  • anonymous
Or even more correctly. It will loop until itersLeft is NOT greater than 0. And each time it executes the body of the loop we move itersLeft closer to that end case. (itersLeft is less than or equal to 0)
anonymous
  • anonymous
i modified the program so it prints from 9 down to 1. i see how the print statement needs to come before the operation on itersLeft in order to start the list at the current value of itersLeft. i don't have a ton of time to continue working on this so i will need to take a break for now. my next step then will be to have the program only print odd numbers?
anonymous
  • anonymous
yes exactly. Have it print the odd ones.
anonymous
  • anonymous
ok. i'll work on that later today or tomorrow and then come back for help if i need it. are you on the open study forum often?
anonymous
  • anonymous
as a hint, think about how far the next odd number is from the current odd number
anonymous
  • anonymous
this forum? or the main openstudy one?
anonymous
  • anonymous
this forum, i suppose.
anonymous
  • anonymous
I'm here often. I don't use the regular openstudy thing as much.
anonymous
  • anonymous
ok, great! that's really nice of you to hang out in an intro forum in order to help us newbies.
anonymous
  • anonymous
I also tutor elsewhere, and I'm hoping to someday teach, so this is good practice =)
anonymous
  • anonymous
well you're off to a good start helping me so i really appreciate it! and, i hope that if you get a job teaching basic CS, it pays well so you aren't scratching your eye balls out over all the dumb questions for nothing.
anonymous
  • anonymous
It's actually pretty rewarding by itself. I've done things that pay well, and they weren't nearly as much fun.

Looking for something else?

Not the answer you are looking for? Search for more explanations.