Latest web development tutorials

Python incluye ejercicios 85

Python 100 Li Python 100 Li

Título: Análisis de un número primo divisible por 9 puede ser varias.

Análisis del programa: Ninguno.

Código fuente:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

if __name__ == '__main__':
    zi = int(raw_input('input a number:\n'))
    n1 = 1
    c9 = 1
    m9 = 9
    sum = 9
    while n1 != 0:
        if sum % zi == 0:
            n1 = 0
        else:
            m9 *= 10
            sum += m9
            c9 += 1
    print '%d can be divided by %d 9' % (sum,c9)

La salida del ejemplo anterior es:

input a number:
9
9 can be divided by 1 9

Python 100 Li Python 100 Li