문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top