Posts by @Jasper_Holton (335)


Nomen mihi est Jasper Camber Holton. scribe, codice, musicam fac, et sum elit Uglek.com.

Has 335 posts, follows 17 users and is followed by 12 users.

Tandem videri at May 24, 2022 10:44



@Jasper_Holton's profile photo

How to Generate a String from a Number in Python I use the following code to generate a string from a number under 1000. It is using simple arrays and if statements to generate a compound number as a string.


import math
n = ['one','two','three','four','five', 'six', 'seven', 'eight', 'nine', 'ten']
tn = ['eleven','twelve','thir','four','fif','six','seven','eigh','nine']
nn = ['teen','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety','hundred']
def number_to_string(num):
    if num < 11:
        return n[num-1]
    if num < 20:
        if num < 13:
            return tn[num-11]
        return tn[num-11] + 'teen'
    if num < 100:
        extra = '-'+n[num%10-1]
        if num%10 == 0:
            extra = ''
        return nn[math.floor(num/10)-1]+extra
    if num < 1000:
        extra = '-'+n[num%10-1]
        if num%10 == 0:
            extra = ''
        return n[math.floor(num/100)-1]+'-hundred-'+nn[math.floor((num%100)/10)-1]+extra
    return 'number too large to compute!'

for x in range(1,1000):
    print(number_to_string(x))


@Jasper_Holton's profile photo

Flowers by Greenlake Now is a beautiful time of year to walk around Greenlake in Seattle. It's really warm and sunny and the lake is beautiful.

Videre photo ex cursore by @Jasper_Holton

@Jasper_Holton's profile photo

Vespere ambulate circa Greenlacum in Seattle Colores verni hoc tempore anni pulchri sunt. exspecto aestas terribilis in Seattle.

Videre photo ex cursore by @Jasper_Holton

@Jasper_Holton's profile photo

Busking by Greenlake in Seattle busk interdum ab aquilone in stagni parte et paulum pecuniae in apicibus fac a meo loco et casu violino. exigua soni exposita a meo busking hodie ut tecum hic communicemus.

Videre photo ex cursore by @Jasper_Holton

@Jasper_Holton's profile photo

Hiking in Washington Multa saepe multa similia sunt his transire ad frontem lacus alpini.

Videre photo ex cursore by @Jasper_Holton

© Uglek, 2022

Terms of Use et Privacy policy