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 - The Fusion of Science and Community**

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

Loading...

Similar Threads - Python woes | Date |
---|---|

Python How can I run Python by getting values from Matlab | Mar 7, 2018 |

Python Interesting article how to use Pandas with Excel sheets | Feb 19, 2018 |

Porting Python Code to Fortran for Parallel Computing | Dec 15, 2017 |

What's wrong with my bisection method code? | Dec 10, 2017 |

Fortran77 woes- single parameter least squares minimisation stuck! | Jan 26, 2014 |

**Physics Forums - The Fusion of Science and Community**