eozzy
eozzy

Reputation: 68710

Leading and Trailing '0' gives error

random.randint(50,9)

or

random.randint(5,09)

give errors, although just

random.randint(5,9)

..works!

Leading and trailing zero's aren't allowed in python without converting it to string or using x.f formatting?

Upvotes: 1

Views: 198

Answers (3)

DreamWave
DreamWave

Reputation: 1940

09 is not a valid dec integer in the second case and in the first case - you have to give the function the lower number first

Upvotes: 0

SilentGhost
SilentGhost

Reputation: 319831

oh, dear. "Trailing" zero gives error because first argument to randint should be smaller than the second.

Leading zeros are used to represent octal numbers in python-2.x as in many other languages.

Upvotes: 6

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799110

A leading 0 means that the value is an octal literal, but 09 is not a valid octal number.

Upvotes: 0

Related Questions