Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top