-2

Each time I put 0 at the beginning of my 7 digit code it is ignored and not times by 3. I have a feeling that I need to change something from str() to int() (and vice-versa) but I may be wrong. I would be grateful for assistance in this matter.

rn01
  • 115
  • 1
  • 1
  • 5
  • Please describe what you want to achieve and what you are doing in your own words, don't just paste your code. – timgeb Jan 27 '16 at 16:32
  • Either you are entering *digits* (characters), or you are entering a *number*. Numbers don't start with 0; that's not part of their numeric value. – Martijn Pieters Jan 27 '16 at 16:34
  • Possible duplicate of [How does python interpret numbers with leading zeroes](http://stackoverflow.com/questions/13431324/how-does-python-interpret-numbers-with-leading-zeroes) – OneCricketeer Jan 27 '16 at 16:35
  • 1
    Are you using Python 2 perhaps? In that case `input()` returns the *Python interpretation* of the input, and not a string. Use `raw_input` in that case. – Martijn Pieters Jan 27 '16 at 16:36
  • @cricket_007: where is the OP using a Python integer literal? – Martijn Pieters Jan 27 '16 at 16:36
  • @MartijnPieters - Guess you're right. That's why it's a *possible* duplicate – OneCricketeer Jan 27 '16 at 16:41

2 Answers2

2

Numeric literals starting with 0 are interpreted as being in base 8.

>>> int("755", base=8)
493
>>> 0755
493
>>> input("> ")
> 0755
493
Vlad
  • 18,195
  • 4
  • 41
  • 71
  • There is no such literal in the code. Perhaps we need to get some clarification from the OP instead? – Martijn Pieters Jan 27 '16 at 16:37
  • if they're using `input()`, and entering `0XYZ`, it might be the same thing. But yes, clarification could help. – Vlad Jan 27 '16 at 16:39
1

Try using raw_input() instead of input(). Input() evaluates the user input as python code, where raw_input() evaluates the entry as entered.

Mike C.
  • 1,761
  • 2
  • 22
  • 46