First day beginner to python, add to counter after nested loop

J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 11:11:17 UTC+1 skrev (e-mail address removed):
Den onsdagen den 30:e oktober 2013 kl. 11:08:11 UTC+1 skrev (e-mail address removed):




Instead of having going over indent manually, you just drop in an end it is so simple, no marking no meny indent unindent it is automaticly done. And that was the purpose of python to remove idiocies, like brackets and indents.

You could have it in the menu indent parser on off. If on you write out ends, and the text is automaticly indented, by using end or a reserved sign. It is quite simple i could program it in a day...
 
C

Chris Angelico

Well Tim ***one could argue*** why not do a (i think it is called parser) that react to "loop", "end" and "function". And lazy like me do not have to think about "what is not part of program".

Python actually does have a symbol for what you're thinking of - but
it's not a keyword. Check this out:

print("Hello, world!")
for i in range(5):
#{
print("Line #%d"%i)
#}

if i>3:
#{
print("After the loop, i is huge!")
#}
else:
#{
print("After the loop, something is seriously screwy.")
raise RuntimeError
#}

ChrisA
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 11:00:30 UTC+1 skrev Mark Lawrence:
On 30/10/2013 09:52, (e-mail address removed) wrote:



Please stop sending us double spaced crap.



--

Python is the second best programming language in the world.

But the best has yet to be invented. Christian Tismer



Mark Lawrence

I think it is not me it is probably google groups, well maybe they should consider changing linebreak sign as stored in database.
 
A

Antoon Pardon

Op 30-10-13 08:07, Tim Roberts schreef:
You only say that because your brain has been poisoned by languages that
require some kind of "end". It's not necessary, and it's extra typing. 99%
of programmers do the indentation anyway, to make the program easy to read,
so why not just make it part of the syntax? That way, you don't
accidentally have the indentation not match the syntax.

Because it is a pain in the ass. Now suddenly my program doesn't work
because I somehow inserted a tab instead of spaces.

The end would also gives extra protection against faulty manipulations.
I have at one time accidently copied a function partly further below.
Because python doesn't need an end, the compilor was unable to detect
this was only part of a function which caused a bug which was harder to
find.

Python made it's choice and I can live with that, but telling people
who prefer it had made an other choice that their brain is poisoned,
only shows you are unable to see the disadvantages.
 
R

rusi

Den onsdagen den 30:e oktober 2013 kl. 11:00:30 UTC+1 skrev Mark Lawrence:

* * Please stop sending us double spaced crap.
* * Mark Lawrence
* I am not sure what you want.

And then again

* You want me to remove the empty line in function? I do it for it is easier to
* read for me.

* I think it is not me it is probably google groups, well maybe they should
* consider changing linebreak sign as stored in database.

1. Go to the python archive for this month
https://mail.python.org/pipermail/python-list/2013-October/author.html#start
2. Search for your posts by control-f jonas
3. Open 4 or 4 at random and try to read them

Now do you see that google-groups (stupidly) inserts extra lines that causes a lot of irritation to a lot of people?
 
C

Chris Angelico

Because it is a pain in the ass. Now suddenly my program doesn't work
because I somehow inserted a tab instead of spaces.

I broadly agree with your post (I'm of the school of thought that
braces are better than indentation for delimiting blocks), but I don't
think this argument holds water. All you need to do is be consistent
about tabs OR spaces (and I'd recommend tabs, since they're simpler
and safer), and you'll never have this trouble. Also, the parser
should tell you if you mix tabs and spaces, so that won't trip
anything either.

ChrisA
 
A

Antoon Pardon

Op 30-10-13 13:17, Chris Angelico schreef:
I broadly agree with your post (I'm of the school of thought that
braces are better than indentation for delimiting blocks), but I don't
think this argument holds water. All you need to do is be consistent
about tabs OR spaces (and I'd recommend tabs, since they're simpler
and safer), and you'll never have this trouble.

Easier said than done. First of all I can be as consistent as possible,
I can't just take code from someone else and insert it because that
other person may be consistenly doing it different from me.

Then if you are working on different machines, the settings of your
editor may not always be the same so that you have tabs on one machine
and spaces on an other, which causes problem when you move the code.

Also when you have an xterm, selecting a tab and pasting it into
another it will turn the tab into spaces.

All these things usually can be ignored, they typically only show
up when you print something and things aren't aligned as you expect
but with python you are forced to correct those things immediatly,
forcing you to focus on white space layout issues instead of on
the logic of the code.
Also, the parser
should tell you if you mix tabs and spaces, so that won't trip
anything either.

Maybe you mean something differen than I understand but a program
throwing a syntax error because there is a tab instead of a number
of spaces or vice versa, is something I would understand as tripping.
 
N

Ned Batchelder

Den onsdagen den 30:e oktober 2013 kl. 11:00:30 UTC+1 skrev Mark Lawrence:
I am not sure what you want.
You want me to remove the empty line in function? I do it for it is easier to read for me.

Jonas, he's talking about the quoted content that Google Groups includes
in your messages. Some people find this extremely aggravating.

As for your code, you should actually give it much more space:

#!/usr/bin/env python
import math

# Function definition is here
def sq(number):
square = 1
factor = 2
multip = exponent * exponent # not sure why exponent is accessed globally..
print(x, "= ", end="")

while number >= multip:
while square <= number:
factor += 1
square = factor * factor
factor -= 1
print(factor, "^", exponent, "+", sep="", end="")
number -= factor*factor
square = 1
factor = 1

print(number)

# Set exponent here
exponent = 3
print("Exp=x^", exponent, sep="")

# Set range of numbers x
for x in range (1, 100):
sq(x)


--Ned.
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 11:11:17 UTC+1 skrev (e-mail address removed):
Den onsdagen den 30:e oktober 2013 kl. 11:08:11 UTC+1 skrev (e-mail address removed):
I suddenly realised i mixed code from a plain square system with the generic exponential modulus system.

Here is the code, what it does is encode numbers in an exponential modulus base. So it is basicly a numbersystem of my own you do not need to write out + ^ and exponent because the numbersystem create unique values for every natural number.

Well without the + ^ it is hard to read but so are binary, ternary and hexadecimal. I think the requirment for a numbersystem is that it have a working arithmetic, and mine have.

So here is the working code, to write out exponential modulus number for and exponent.

#!/usr/bin/python
import math
# Function definition is here
def sq(number):

exp=1
factor=2
multip=math.pow(2,exponent)
print(x,"= ", end="")
while number>=multip:
while exp<=number:
factor+=1
exp=math.pow(factor,exponent)
factor-=1
print(factor,"^",exponent,"+",sep="",end="")
exp=math.pow(factor,exponent)
number=number-exp
exp=1
factor=1
print(number)

#Set exponent here
exponent=2
print("Exp=x^",exponent,sep="")
#Set range of numbers x
for x in range (1,100):
sq(x)
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 15:22:50 UTC+1 skrev Alister:
I disagree it is very easy.



1) make sure you editor is set to inset 4 spaces rather than tab when

pressing the tab key. consistency in your own code is now not an issue.



2) when importing code from someone else a simple search & replace of tab

with 4 spaces will instantly correct the formatting on code using tab

without breaking code that doesn't.










that is fixed by setting your environment consistantly but step 2 above

will fix it if you forget.







Read pep 11 & always use 4 spaces for indentation not tab.












no more than failing to close a brace in a C like language

indentation is the syntax of python you will grow to love it, like most

people I found it distracting at first even though i tended to indent

other code (inconsistently)to make it readable.

Alister i do not ask for changing the actual implementation with indents that the compiler/interpretator work with. What i ask for is some courtesy relative the programmers using IDLE, to incorporate a simple automatic parserthat let them who like to write slopy formatted with end instead to do so.And the parser in editor automaticly go in and autoindent *function, loops, if and allow end that the editor autoindent to end of loop. It can not bethat hard i have implemented my own python using this...
 
A

Antoon Pardon

Op 30-10-13 15:22, Alister schreef:
I disagree it is very easy.

You can disagree, as much as you want. You don't get to define my
experience. Maybe all those things you enumerate are all easy, all
taken together they can makes it cumbersome at times.
1) make sure you editor is set to inset 4 spaces rather than tab when
pressing the tab key. consistency in your own code is now not an issue.

2) when importing code from someone else a simple search & replace of tab
with 4 spaces will instantly correct the formatting on code using tab
without breaking code that doesn't.

But why should I have to do all that. When I write other code I just
don't have to bother and it is all indented as desired too.
that is fixed by setting your environment consistantly but step 2 above
will fix it if you forget.

Again why should I have to bother. Why does python force me to go
through all this trouble when other languages allow themselves to
be happily edited without all this.
Read pep 11 & always use 4 spaces for indentation not tab.

I'll decide how to layout my code.
no more than failing to close a brace in a C like language
indentation is the syntax of python you will grow to love it, like most
people I found it distracting at first even though i tended to indent
other code (inconsistently)to make it readable.

I didn't like it at first, accustomed to it a bit and then disliked it
again. So no I don't think I will grow to love it. Python is a tool,
not a religion, so I can live with it if the tool I use has some
featurese I dislike about it. As long as I evaluate the usefulness of
the tool as positive I can live with the peeves.

What is more annoying are the people with some kind of need to reason
your peeves away, as if it is sacriledge daring to dislike something
about the language.
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 16:09:25 UTC+1 skrev Mark Lawrence:
On 30/10/2013 14:31, (e-mail address removed) wrote:



Would you please be kind enough to read, digest and action this

https://wiki.python.org/moin/GoogleGroupsPython



TIA.



--

Python is the second best programming language in the world.

But the best has yet to be invented. Christian Tismer



Mark Lawrence

I am all for automatiation to be honest i rather go in change the code for google than do it manual. Maybe those who complain should adress Google? There must be a simple solution or?
 
G

Grant Edwards

Op 30-10-13 08:07, Tim Roberts schreef:

Because it is a pain in the ass. Now suddenly my program doesn't work
because I somehow inserted a tab instead of spaces.

Then don't do that.

I'm only half-kidding. Inserting incorrect tokens into program source
breaks programs in all languages. The tricky bit is that in many
editors spaces and tabs look the same. You can pick an editor that
provides a visual difference, or you can pick an editor that always
does the right thing, or you can stick with it until your fingers
learn to do the right thing.
The end would also gives extra protection against faulty
manipulations. I have at one time accidently copied a function partly
further below. Because python doesn't need an end, the compilor was
unable to detect this was only part of a function which caused a bug
which was harder to find.

Python made it's choice and I can live with that, but telling people
who prefer it had made an other choice that their brain is poisoned,
only shows you are unable to see the disadvantages.

Those of us who've been using Python for more than a few days think it
is you who are unable to see the advantages. ;)

Whether allowing indentation via either tabs or spaces was a
fundamental design flaw has long been debated. Personally, I think
tabs should be outlawed in all source code...
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 16:35:29 UTC+1 skrev (e-mail address removed):
Den onsdagen den 30:e oktober 2013 kl. 16:09:25 UTC+1 skrev Mark Lawrence:




I am all for automatiation to be honest i rather go in change the code for google than do it manual. Maybe those who complain should adress Google? There must be a simple solution or?

Another solution would of course be use a newsreader that can do it for you?
 
R

rusi

Den onsdagen den 30:e oktober 2013 kl. 16:09:25 UTC+1 skrev Mark Lawrence:
I am all for automatiation to be honest i rather go in change the code for
google than do it manual. Maybe those who complain should adress Google?
There must be a simple solution or?

A fully automatic solution would be for google to stop screwing up :)
One step less is to have some kind of javascript (greasemonkey??) plugin for firefox to cleanup GG's mess

Since I dont pretend to know JS/greasemonkey, I have made a small emacs script.
It involves
1. cut-pasting from browser to emacs
2. pressing a key
3. Cut pasting back

More details https://groups.google.com/forum/#!topic/comp.lang.python/Imo2m4GrS_I

So...
4 choices:

1. Do it by hand
2. Do it by emacs
3. Ignore and get unpopular
4. Dont use Google Groups
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 16:50:43 UTC+1 skrev Grant Edwards:
Then don't do that.



I'm only half-kidding. Inserting incorrect tokens into program source

breaks programs in all languages. The tricky bit is that in many

editors spaces and tabs look the same. You can pick an editor that

provides a visual difference, or you can pick an editor that always

does the right thing, or you can stick with it until your fingers

learn to do the right thing.












Those of us who've been using Python for more than a few days think it

is you who are unable to see the advantages. ;)



Whether allowing indentation via either tabs or spaces was a

fundamental design flaw has long been debated. Personally, I think

tabs should be outlawed in all source code...



--

Grant Edwards grant.b.edwards Yow! Uh-oh!! I'm having

at TOO MUCH FUN!!

gmail.com

I think the idea with tab indentation would been it is an easy road for automation. I think it is easily that project goes anal when let over to code monkeys, maybe that is the case.
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 16:54:19 UTC+1 skrev Mark Lawrence:
The simplest solution is that you stop posting, as you've been spewing

this double spaced crap all day and show no inclination to do anything

about it. I assume that google won't fix their problem as there's not

enough profit in it.



--

Python is the second best programming language in the world.

But the best has yet to be invented. Christian Tismer



Mark Lawrence

Bug of anal monkey either solve your own problems, or implement your own newsreader.
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 16:51:58 UTC+1 skrev Alister:
Google are unlikely to change any time soon, if you do not compensate for

there bad behaviour many people here will start to ignore your posts.



I agree it is a pain, & it is not your fault but these are the basic

facts.







--

A rolling stone gathers no moss.

-- Publilius Syrus

Well i ain't going to change so i promise unless the spaceout rows fill some purpose it is Google who is going to change.

Google groups work good for me and i certainly have no intention to change newsreader, but i agree Google should have done something about this years ago *if the empty lines fill no purpose*. And they did a mayor change a couple of years ago, it is a mystery they could not fix this if it serve no purpose?
 
R

rusi

Den onsdagen den 30:e oktober 2013 kl. 16:54:19 UTC+1 skrev Mark Lawrence:
Bug of anal monkey either solve your own problems, or implement your own newsreader.

Yes I guess if Mark speaks in that way he will get that kind of response. (Sigh)

However Jonas, please remember that this list is read by thousands.
And by posting 5 times more lines than is relevant to the discussion you are making a nuisance of yourself to all those readers.
 
J

jonas.thornvall

Den onsdagen den 30:e oktober 2013 kl. 16:54:19 UTC+1 skrev Mark Lawrence:
The simplest solution is that you stop posting, as you've been spewing

this double spaced crap all day and show no inclination to do anything

about it. I assume that google won't fix their problem as there's not

enough profit in it.



--

Python is the second best programming language in the world.

But the best has yet to be invented. Christian Tismer



Mark Lawrence

For what *they* actually have done is replacing the curl paragraph slavery with indentation slavery. And looking at the other features of python i easily can tell that was not the intention of the creator, it was to remove the anal code monkey stuff and replace it with simplicity and automation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top