Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #108582
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Average calculation Program *need help* |
| Date | 2016-05-12 23:29 -0600 |
| Message-ID | <mailman.625.1463117393.32212.python-list@python.org> (permalink) |
| References | (1 earlier) <dab38f98-4ba3-4673-bfb3-e2aa676c9110@googlegroups.com> <57355EA6.50905@gmail.com> <mailman.621.1463115436.32212.python-list@python.org> <26884493-24d4-4d3d-b7d8-816f043b28b7@googlegroups.com> <5735664B.8000506@gmail.com> |
On 05/12/2016 11:03 PM, Jake Kobs wrote:
> Im not sure how to move it inside the for loop. I've been working on
> this small problem for like 4 hours lol.
I'm sorry it's so frustrating. Sounds like you haven't got down some of
the most basic fundamentals yet. In Python, things that should happen
one after another are placed at the same indent level on the screen.
For example:
if something:
do_this()
then_this()
then_that()
Everything indented in from the start of the if statement is in a block
and only happens if the if statement condition is true. If there're
statements at the same level as the if, then they happen *after* the if
and it's block. In other words, indentation is what tells Python where
you want things to run. If you want to move the while loop inside the
for loop, you have to adjust it's indentation accordingly (and the
indentation in it's own block).
This is a big gotcha for people unfamiliar with programming in Python,
and unfamiliar with programming in general. In other languages, indents
don't have to be a certain way, as long as you have the write statements
to close off the loop. However, Python's method forces you to think
like a programmer and to lay things out on the screen in a logical
fashion, like a writer's outline.
If you're still stuck, you will probably want to sit down with your
teacher and have him or her go over this with you. This is important
basic stuff you need to have clear in your mind to program computers.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Average calculation Program *need help* kobsx4@gmail.com - 2016-05-12 08:47 -0700
Re: Average calculation Program *need help* Rustom Mody <rustompmody@gmail.com> - 2016-05-12 09:01 -0700
Re: Average calculation Program *need help* Igor Korot <ikorot01@gmail.com> - 2016-05-12 12:06 -0400
Re: Average calculation Program *need help* DFS <nospam@dfs.com> - 2016-05-12 19:45 -0400
Re: Average calculation Program *need help* "Martin A. Brown" <martin@linux-ip.net> - 2016-05-12 09:13 -0700
Re: Average calculation Program *need help* MRAB <python@mrabarnett.plus.com> - 2016-05-12 17:14 +0100
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-12 21:22 -0700
Re: Average calculation Program *need help* Ben Finney <ben+python@benfinney.id.au> - 2016-05-13 14:55 +1000
Re: Average calculation Program *need help* Michael Torrie <torriem@gmail.com> - 2016-05-12 22:57 -0600
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-12 22:03 -0700
Re: Average calculation Program *need help* Michael Torrie <torriem@gmail.com> - 2016-05-12 23:29 -0600
Re: Average calculation Program *need help* DFS <nospam@dfs.com> - 2016-05-13 01:12 -0400
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-12 22:46 -0700
Re: Average calculation Program *need help* Nick Sarbicki <nick.a.sarbicki@gmail.com> - 2016-05-13 07:10 +0000
Re: Average calculation Program *need help* Jake Kobs <kobsx4@gmail.com> - 2016-05-13 08:38 -0700
Re: Average calculation Program *need help* DFS <nospam@dfs.com> - 2016-05-13 12:17 -0400
csiph-web