Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26594
| Date | 2012-08-06 01:58 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Getting started with IDLE and Python - no highlighting and no execution |
| References | <d07282d6-1666-4230-bf46-c0942ef9a390@r7g2000yqr.googlegroups.com> <jvn1vr$ln6$1@dont-email.me> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2991.1344214708.4697.python-list@python.org> (permalink) |
On 06/08/2012 01:09, Rotwang wrote: > On 06/08/2012 00:46, PeterSo wrote: >> I am just starting to learn Python, and I like to use the editor >> instead of the interactive shell. So I wrote the following little >> program in IDLE >> >> # calculating the mean >> >> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] >> >> def mean(data): >> return sum(data)/len(data) >> >> mean(data1) >> >> >> There is no syntax highlighting and when I ran it F5, I got the >> following in the shell window. >> >> >> >>> ================================ RESTART >> ================================ >>>>> >>>>> >> >> >> Any ideas? > > I don't know what editor you're using or how it works, but I'm guessing > that pressing f5 runs what you've written as a script, right? In that > case the interpreter doesn't automatically print the result of > expressions in the same way that the interactive interpreter does; you > didn't tell it to print anything, so it didn't. > It looks like it's IDLE. > >> If I added print mean(data1), it gave me a invalid syntax >> Which suggests to me that it's Python 3. >> # calculating the mean >> >> data1=[49, 66, 24, 98, 37, 64, 98, 27, 56, 93, 68, 78, 22, 25, 11] >> data2=[1,2,3,4,5] >> >> def mean(data): >> return sum(data)/len(data) >> >> mean(data1) >> print mean(data1) > > If you're using Python 3.x, you'll need to replace > > print mean(data1) > > with > > print(mean(data1)) > > since the print statement has been replaced with the print function in > Python 3. > > If you're instead using Python 2.x then I don't know what the problem > is, but in that case your mean() function won't work properly - the > forward slash operator between a pair of ints gives you floor division > by default, so you should instead have it return something like > float(sum(data))/len(data). >
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Getting started with IDLE and Python - no highlighting and no execution PeterSo <ojlise@gmail.com> - 2012-08-05 16:46 -0700
Re: Getting started with IDLE and Python - no highlighting and no execution Rotwang <sg552@hotmail.co.uk> - 2012-08-06 01:09 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution MRAB <python@mrabarnett.plus.com> - 2012-08-06 01:58 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution Matthew Barnett <mrabarnett@mrabarnett.plus.com> - 2012-08-06 02:01 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution Rotwang <sg552@hotmail.co.uk> - 2012-08-06 02:13 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution PeterSo <ojlise@gmail.com> - 2012-08-05 19:17 -0700
Re: Getting started with IDLE and Python - no highlighting and no execution Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-06 01:52 +0100
Re: Getting started with IDLE and Python - no highlighting and no execution Terry Reedy <tjreedy@udel.edu> - 2012-08-05 21:32 -0400
Re: Getting started with IDLE and Python - no highlighting and no execution soloflyr@gmail.com - 2012-08-09 06:36 -0700
csiph-web