[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
looking for some programming fag to explain this to me. step
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.
The stories and information posted here are artistic works of fiction and falsehood.
Only a fool would take anything posted here as fact.
You are currently reading a thread in /b/ - Random

Thread replies: 66
Thread images: 3
File: pythonlogo.jpg (46 KB, 680x459) Image search: [Google]
pythonlogo.jpg
46 KB, 680x459
looking for some programming fag to explain this to me. step by step if you have the time.


x = 7
y = x + 1
while y < 100:
y = y * y

print(y)

What does y print?


i know i sound retarded but how can y be greater than 100?
>>
but y isnt greater than 100
>>
>>693514596
Because y is less than 100 before it gets squared, but then you square it and then print it
>>
64
>>
>>693514893
this
you check if the condition is true, it is, lets say y is 50, its under 100 but then you do 50*50, thats alot higher than 100
>>
>>693514808
>>693514893
>>693514999
im trying to understand how this works. and one of you break it down for me
>>
>>693514596
4096
>>
>>693514999
dumbass
>>
>>693514596
map it out on a piece of paper, it isn't hard.
get your y by inserting x. = ?
then (while y is < 100) multiply y by itself
? * ? = new y = ??
is it less than 100? if so, do it again
?? * ?? = new y = ??? is it less than 100? if so do it again
??? * ??? = new y =???? etc, etc etc. Do your own homework.
>>
>>693515178
quoi?
>>
>>693514596
assuming the line y = y * y is meant to be indented, you should get 65536 as output

y starts off with a value of 8
it's less than 100, so we calculate 8 * 8 which is 64 and change y's value to that.
having reached the last indented line we wrap around to check the condition (while y less than 100) again - it's still true so we update y to the value of 64 * 64
now the condition is false so we print the current value of y, which should be 65536
>>
When y enters the while loop, it's 8.

While 8 < 100 = true

We go into the loop and multiply 8 * 8 and assign it back to y...y now equals 64

we go back up to the while loop condition to check if 64 < 100

64 is less than 100, so we go back into the loop

64 * 64 = 4,096

y now equals 4,096.

We go back up to the while loop to check if 4,096 < 100

It's not true, so we break out of the while loop and print y (which is 4,096)

y prints 4,096
>>
>>693514596
how can you not understand this lol?
>>
>>693514596
x=7
y=7+1 , so eight
while y is less than 100, set it equal to itself squared, so 64. but we're still in the while loop since y is less than 100, so we square again. now y equals 4096 which is > 100, so you print out y
>>
>>693515275
next time i will not do math in my head
>>
>>693515356
op here. because im an uneducated dumb ass but im trying to learn
>>
>>693515345
This. All other answers are troll.
>>
>>693515356
He's doing more than most wannabee programmers. Help or fuck off.
>>
>>693515111
8*8=64

is that less than 100?
yes

64*8=512
Is that less than 100?
no
ok exit the while loop

print y
>>
>>693515486
Uneducated has nothing to do with it. You just don't want to follow directions. The entire problem is literally common sense. Stop being lazy.
>>
>>693515345
+1 good step by step explanation
>>
>>693515486
you don't even need to know how to read/write code, but every 5th grader should be able to understand this
>>
>>693515619
Wrong, 64*64, since 64 is the new y after the first loop.
>>
>>693515345
thank you, anon. this really helps
>>
>>693515611
Welp, if he wants to 'do' something he should buy a book about python: https://www.amazon.com/Learning-Python-5th-Mark-Lutz/dp/1449355730/ref=sr_1_1?ie=UTF8&qid=1467932411&sr=8-1&keywords=learning+python
>>
>>693514596
>x = 7
>y = x + 1
>while y < 100:
>y = y * y
>print(y)


y is 8
8<100 -> y=8*8 -> y=64

64<100 -> y=64*64 -> y=4096

4096>100 -> print 4096
>>
>>693514596

y doesn't print, you get a syntax error. You forgot to indent the loop.

kek
>>
>>693515790
>>693515790
yes you are right, brain fart on my part

see
>>693515345
>>
>>693514596

x = 7
y = 7 + 1
y = 7 * 7
y = 49
y = 49 * 49
y = 2401
fin
>>
>>693515275
Right logic, wrong solution.

>>693515345
correct

>>693515404
right

>>693515619
almost right

>>693515877
yep
>>
>>693515651
im not trying to be rude but did you even read my post? i said im not educated. i went to a shit school all my life so my education is shit. im not ok with that so im trying to better my self.
>>
>>693516003
7+1 != 7...
>>
>>693516003
whoops should be
x = 7
y = 7 + 1
y = 8 * 8
y = 64
y = 64 * 64
y = 4096
fin
>>
>>693514596
Lol, what retard has written this? How can you do 'y = y*y' instead of 'y *= y'....
>>
>>693516176
Works in python too ?
>>
>>693514596
add a fucking space before the line after the while loop too. filthy savage.
>>
>>693516176
not op but it's the same you autistic cancer nigger
>>
you must focus on the value of your parameter y at the enter of the loop, after, you just follow the loop, here you will have y=64*64 be print.(i begin python 3 months ago)
>>
Add a loop, and yeah y = 8 * 8
Then y changes to 64 * 64
then y is now grater then 100 so it will stop @ 4096..
>>
>>693515262

Abrutis
>>
>>693514596
Everyone here is wrong.

The ouput will be as follows:

64
4096
>>
>>693516565
the print is outside the loop faggot, it only prints the last value
>>
>>693516394
Yeah but why write more code than you need to lol, as if I wouldn't know that it is the same you fucking pleb.
>>
OP here. can one of you point me in the right direction to learn this stuff? i know im retarded/autistic and any other insult you throw at me but i do want to learn
>>
nothing because you didn't indent faggot
>>
>>693516060

KEEP GOING BRO, THAT'S A GREAT THING YOU'RE DOING.

this site will show you step by step what the program is doing

http://www.pythontutor.com/
>>
>>693516813
thank you anon. ill take this to heart.
>>
>>693516756
Learn embedded C, Python is for girls

https://www.edx.org/course/embedded-systems-shape-world-utaustinx-ut-6-03x
>>
>>693516813
Don't use websites, you don't want to learn programming from pajeets, just buy a book.
>>
>>693516955
What is ruby for then?
>>
>>693516756
Read some book of O'reilly
>>
>>693517058
thank you. ill look in to that
>>
>>693516756

Reddit, I'm serious. /r/learnpython has some good resources in the wiki
>>
Take a piece of paper, you'll be surprised how many codes were written first on paper.
Here is your code, line by line:
>1) x = 7
>2) y = x + 1
>3) while (y<100) {
>4) y = y * y }
>5) print (y)

Remember that a computer is dumb, hence can only execute one line at a time. So here it is step by step:
>1: 1) x = 7
>2: 2) y = x + 1 = 7 + 1 = 8
>3: 3) is y < 100? 8 <100 ? True so go to 4)
>4: 4) y = y * y = 8 * 8 = 64
>5: Back to the condition since we're done with this line, so back to 3) is y < 100? is 64 < 100? True so go do 4) again
>6 : 4) 64*64= 4096
>7: Back to the condition, is y <100? 4096 < 100? FALSE so we don't execute the line in the while, we skip line 4)
>8: We now execute 5), print y, thus print 4096.

Remember it's not because we left the while loop that what happened in it is discarded. Y changed and even though y no longer respect the while condition y is still 64 * 64.
>>
>>693517037
Whores
>>
>>693516955
Not recommending well known books:
https://www.amazon.com/Programming-Language-Brian-W-Kernighan/dp/0131103628/ref=sr_1_1?s=books&ie=UTF8&qid=1467932925&sr=1-1&keywords=the+c+programming+language
>>
File: snoopie.jpg (80 KB, 300x300) Image search: [Google]
snoopie.jpg
80 KB, 300x300
>>693516756

I think the python doc is pretty much self-explanatory. If you don't understand it, its probably because you don't understand the basics.
>>
File: 1461523857947.jpg (18 KB, 236x284) Image search: [Google]
1461523857947.jpg
18 KB, 236x284
>>693517143
thank you for the chuckle
>>
>>693516756
Youtube has tons of tutorials. It's how I learned throughout college.

Also, Codecademy has a whole 10 hour interactive course on Python for free.

I'd really recommend Derek's Banas's "Learning to Program" series on Youtube right now. I wish I had it when I was a programming noob years ago.

https://www.youtube.com/watch?v=nwjAHQERL08
>>
>>693517229
OP here. ive looked at it and to me it looks like hyroglifics
>>
and if you need help on your code, go on stackoverflow ;D
>>
>>693516756
Just don't use any websites besides the official documentaries, buy books.
>>
>>693514596

https://www.codecademy.com/

https://www.udacity.com/course/programming-foundations-with-python--ud036

https://www.edx.org/course/introduction-computer-science-mitx-6-00-1x-8

codeacademy is really basic but it's a good start, i haven't done the udacity one but they say it's really good. the edx one is pretty hard (imo) but it's probably the best one.

also reddit learnprogramming FAQ
>>
>>693517214

That course has a lot of interaction in it. You can download and work on their IDE and have a virtual microcontroller on your machine. It also is a video course, next best thing from going to a university to learn this.

But I agree with you about Kernighan's book.
>>
>>693517627
Thank you, ill look in to all of them
>>
>>693515896
Really the only correct answer here.
Thread replies: 66
Thread images: 3

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.