Python Forum

Full Version: create three digit numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello!

I would like to get all the 3 digit numbers where, the digit on the right side is equal or bigger than the previos one (on its left). Like: 112, 122,123 are okay but 132 is not good.
Could you give some hint to get all the combinations? Thank you
What have you tried? Shouldn't this be in the 'homework' section?
Hello!

I would like to get all the 3 digit numbers where, the digit on the right side is equal or bigger than the previos one (on its left). Like: 112, 122,123 are okay but 132 is not good.
Could you give some hint to get all the combinations? Thank you
create a digit numbers list and ask for

mydigits = [112, 122, 123]
the_digit = input('Enter Digit:\n')
if int(the_digit) in mydigits:
    print('Digit OK')
else:
    print('Digit not OK') 
like this?:

result = []

for nb in range(100,1000):
    nb_str = str(nb)
    if int(nb_str[0]) <= int(nb_str[1]) and int(nb_str[1]) <= int(nb_str[2]):
        result.append(nb)
      
print(result)