Andre_P
Posts: 241
Joined: Sun Aug 28, 2011 7:57 am

Re: Python Hello World :)

Wed Mar 21, 2012 10:25 pm

Yes I know to all you uber Software types this must be amazingly trivial but, but I've got

1. got "Hello World" displayed

2. discovered that printing 22/7 generates a rounded down integer

all in Python .

No it's not on an RPi, it's just on the command line on my Mac. It's been ages since I put something together in a new language. I think the first time I did something in Perl was about 10 years ago, Tcl about 7 years ago and PSL I don't think of as a language but a nightmare !

I'm using the O'Reilly books as I've enjoyed using them before and while I am sure the online stuff is excellent I rather like a book. Also note lugging the Learning and Programming books all the way from Foyles (famous bookshop in London) back to Southampton developed some muscle tone !

User avatar
Jongoleur
Posts: 1179
Joined: Thu Aug 11, 2011 12:47 pm
Location: O'erlooking the sea, and all those effin windfarms...

Re: Python Hello World :)

Wed Mar 21, 2012 11:03 pm

Andre_P said:

...
2. discovered that printing 22/7 generates a rounded down integer

all in Python .

...

Yep, div does that..... 

Ok - who else approximates Pi by doing 22/7 ??????  
I'm just a bouncer, splatterers do it with more force.....

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: Python Hello World :)

Wed Mar 21, 2012 11:26 pm

Jongoleur said:


Ok – who else approximates Pi by doing 22/7 ??????  


Well, Ancient Egyptians and Archimedes (22/7 as an upper bound) to name a few.  22/7 is a (slightly) better approximation for pi than 3.14 -- that's why European pi day 22 July is more accurate than American pi day March 14

Andre_P
Posts: 241
Joined: Sun Aug 28, 2011 7:57 am

Re: Python Hello World :)

Wed Mar 21, 2012 11:38 pm

Good, glad you spotted it

Seriously I am glad that I've found out now that Python in that mode at least does integer math, I hope that there is a way of doing floating point stuff. I'd rather not have to write some kind of routine to that kind of thing.

It's bad enough having to do SCR Base and Extension math in VHDL !

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: Python Hello World :)

Wed Mar 21, 2012 11:48 pm

Andre_P said:

Seriously I am glad that I've found out now that Python in that mode at least does integer math, I hope that there is a way of doing floating point stuff. I'd rather not have to write some kind of routine to that kind of thing.
I don't know Python, but you might try "22.0/7.0".

Isceald Glede
Posts: 7
Joined: Sat Mar 17, 2012 12:26 pm

Re: Python Hello World :)

Thu Mar 22, 2012 6:40 am

The meaning of / changed from python3:

Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 22/7
3

Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 22/7
3.142857142857143

The if you want to get 3, use 22//7, which also works in python < 3. If you want ?, use:

from math import pi

Andre_P
Posts: 241
Joined: Sun Aug 28, 2011 7:57 am

Re: Python Hello World :)

Thu Mar 22, 2012 6:52 am

John : Just tried it and yes that does work, thank you

Isceald : Just got the version number, 2.7.1, I guess this explains stuff . Thank you for the pointer

As I say this is the very first outing, I rather like the idea I'm already finding interesting stuff about the language already, I sincerely hope this is the kind of thing that will intrigue the kids .

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Python Hello World :)

Thu Mar 22, 2012 9:55 am

Jongoleur said:


Ok – who else approximates Pi by doing 22/7 ??????  



There's a blast from the past! It was a useful form in the pre-calculator days if you were working with pencil paper; if you used a slide rule then you didn't need it because pi was marked on the scales. 22/7 is accurate to three significant figures, which was the sort of level we worked to much of the time anyway - if you needed better than that then you reached for the four-figure or five-figure log tables and things became much more tedious.

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Python Hello World :)

Thu Mar 22, 2012 10:01 am

And of course we had books in which we could look up the value of pi, or other necessary constants, to the required level of accuracy.

Andre_P
Posts: 241
Joined: Sun Aug 28, 2011 7:57 am

Re: Python Hello World :)

Thu Mar 22, 2012 10:12 am

exartemarte : Curiously enough it was for the want of producing Log tables that Babbage started to put the Difference Engine together. I feel the circle is being completed .

Note I did use a Slide Rule one single time, it came with a geometry set.

User avatar
piglet
Posts: 911
Joined: Sat Aug 27, 2011 1:16 pm

Re: Python Hello World :)

Thu Mar 22, 2012 10:33 am

Meh! Lightweights! We wiled away the tedious minutes in one all-school-assembly memorising Pi. We got to around 100 digits.

*Thinks and types*

3.1415926535897932384626433832...ummmmm...no. Stumped.

*Looks up and Checks*

3.1415926535897932384626433832795028841971

Yay! 30 years later and I can still remember the first 28 decimal places.

Alchemy
Posts: 92
Joined: Mon Jan 30, 2012 2:10 pm

Re: Python Hello World :)

Thu Mar 22, 2012 11:33 am

Great to see people learning instead of waiting.

I use a Python version compatible with Blender(it's inside a CAD). Apologies if this syntax isn't universal.

>import math

>math.pi-(math.log(math.pow(640320.,3)+744.)/math.pow(163,.5))

>import cmath

>cmath.phase(complex(-1.0,0.0))

Ravenous
Posts: 1956
Joined: Fri Feb 24, 2012 1:01 pm
Location: UK

Re: Python Hello World :)

Thu Mar 22, 2012 11:51 am

Pah.  Everybody knows pi is three, ish.

In fact it can be as low as two. Especially if you draw a big circle around the Earth's equator and take the ratio of the circle's circumference to its diameter, which is surely the definition of pi.

(Assuming the Earth is a perfect sphere of course - no polar flattening, etc.)

User avatar
johnbeetem
Posts: 945
Joined: Mon Oct 17, 2011 11:18 pm
Location: The Mountains
Contact: Website

Re: Python Hello World :)

Thu Mar 22, 2012 2:55 pm

piglet said:


Meh! Lightweights! We wiled away the tedious minutes in one all-school-assembly memorising Pi. We got to around 100 digits.


Having a good mnemonic helps:


How I need a drink -- alcoholic of course -- after the heavy lectures involving quantum mechanics.


There's a French version with 126 digits: Wikipedia.

2+2?  Brain the size of a planet and you're asking me to add 2+2?

User avatar
panik
Posts: 369
Joined: Fri Sep 23, 2011 12:29 pm
Location: Netherlands

Re: Python Hello World :)

Thu Mar 22, 2012 4:42 pm

Or:

>>> import math

>>> math.atan(1) * 4
Microcontroller addon boards and software for Raspberry Pi A+/B+/Pi2:
- ARMinARM: ARM Cortex-M3 (STM32)
- AVRPi: ATmega32U4 & ATmega328 ("Arduino")
http://www.onandoffables.com

Garzini
Posts: 2
Joined: Tue Mar 20, 2012 10:11 pm

Re: Python Hello World :)

Thu Mar 22, 2012 9:55 pm

John Beetem said:


piglet said:


Meh! Lightweights! We wiled away the tedious minutes in one all-school-assembly memorising Pi. We got to around 100 digits.


Having a good mnemonic helps:


How I need a drink — alcoholic of course — after the heavy lectures involving quantum mechanics.


There's a French version with 126 digits: Wikipedia.


The Mnemonic I was taught had less digits, but was more relevant:

How I Wish I Could Calculate Pi

User avatar
SN
Posts: 1014
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Python Hello World :)

Thu Mar 22, 2012 10:03 pm

I've always been able to remember PI to 3.1415926535 - the 535 bit on the end was easy
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

User avatar
exartemarte
Posts: 373
Joined: Sat Mar 03, 2012 3:51 pm
Location: Middle England
Contact: Website

Re: Python Hello World :)

Thu Mar 22, 2012 10:43 pm

When I was at school, everyone knew that pi was 3.1416 - which was what you had to look up in the log tables to use it in calculations. When I first studied engineering, and had to use five-figure logs, I felt quite smug about knowing that pi was really 3.14159 ...

Return to “Python”