python woes:(adsbygoogle = window.adsbygoogle || []).push({});

Code (Text):~/code/python$ cat five.py

#!/usr/bin/env python

x = input('Enter a five digit number: ')

while (not(x < 10000 and x > 99999)):

x = input('Five digits please: ')

firstDigit = x / 10000

secondDigit = (x / 1000) % 10

thirdDigit = (x / 100) % 10

fourthDigit = (x / 10) % 10

fifthDigit = x % 10

print "The digit a is", firstDigit, secondDigit, thirdDigit, fourthDigit, fifthDigit

(1)~/code/python$ ./five.py

Enter a five digit number: 54

Five digits please: 54321

Five digits please: dang

Traceback (most recent call last):

File "./five.py", line 5, in ?

x = input('Five digits please: ')

File "<string>", line 0, in ?

I don't understand why it asks for five digits again.

My original code was this:

The statements should have been equivalent but it causes problems when I do it the first way.Code (Text):x = input('Enter a five digit number: ')

while (x <= 9999 or x >= 99999):

x = input('Five digits please: ')

In java:

x = input.nextInt();

while (!(x > 10000 && x < 99999))

{

System.out.println("Five digits retard: ");

x = input.nextInt();

}

It works like it's supposed to i believe.

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Python woes

**Physics Forums | Science Articles, Homework Help, Discussion**