Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 19th, 2013, 02:24 PM
pr0x1mity pr0x1mity is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 pr0x1mity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 51 sec
Reputation Power: 0
Syntax help

Okay I'm learning to program in Python. I don't have previous programming experience. I'm not a math guy, so could you please recommend me some good books to learn math.

Why is this invalid:

>>> zip_code = 02492
SyntaxError: invalid token

Why is this valid:

>>> zip_code = 02132
>>> zip_code
1114

I'm getting a semantic error :/

It has something to do with the way numbers are multiplied/divided I think.

>>> 01
1
>>>010
8
>>> 0100
64
>>> 01000
512
>>> 010000
4096

Reply With Quote
  #2  
Old January 19th, 2013, 04:05 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
Looks like a leading 0 digit indicates octal notation.

Base 8.

Use strings for zip codes

PennPlaza = '10001'

ooops, bad example.

zip = '01234'

# better
Comments on this post
pr0x1mity agrees: Very useful and really helpful
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 19th, 2013, 04:28 PM
pr0x1mity pr0x1mity is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 pr0x1mity User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 51 sec
Reputation Power: 0
Thanks a lot! What's a good base 8 book that I could learn from?

Reply With Quote
  #4  
Old January 19th, 2013, 05:54 PM
Nyktos Nyktos is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 74 Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level)Nyktos User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 2 h 22 m 37 sec
Reputation Power: 2
As a general rule, if you aren't going to do math on something, don't treat it as a number, even if it is composed to numerals.

(Incidentally, treating numbers with a leading 0 as octal was eliminated in Python 3.)
Comments on this post
pr0x1mity agrees: Gave general helpful guidelines to beginning programmers
Dietrich agrees: a good reminder

Reply With Quote
  #5  
Old January 19th, 2013, 08:38 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
I like base 0.

Code:
   0b1 0b5 0ba 0bz 0b85manyzeros93472  NB. base 0
1 5 10 35 2

   0.1b345   NB. base 0.1
5.43

   _3b123    NB. base negative 3
6

   (3*(-3)^0) + (2*(-3)^1) + (1*(-3)^2)
6

   4r3p1  NB. 4 pi over 3
4.18879
   
www.jsoftware.com

Last edited by b49P23TIvg : January 19th, 2013 at 08:43 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Syntax help

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap