题解 | #学英语#
学英语
https://www.nowcoder.com/practice/1364723563ab43c99f3d38b5abef83bc
n = int(input()) ones = { 0: "", 1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 10: "ten", 11: "eleven", 12: "twelve", 13: "thirteen", 14: "fourteen", 15: "fifteen", 16: "sixteen", 17: "seventeen", 18: "eighteen", 19: "nineteen", } tens = { 2: "twenty", 3: "thirty", 4: "forty", 5: "fifty", 6: "sixty", 7: "seventy", 8: "eighty", 9: "ninety", 1: "ten", } def transfer(attr): if 0 <= attr <= 19: return ones[attr] elif 20 <= attr <= 99: return tens[attr // 10] + ["" if attr % 10 == 0 else " "][0] + ones[attr % 10] elif 100 <= attr <= 999: return ( ones[attr // 100] + " hundred " + ["" if attr % 100 == 0 else "and "][0] + transfer(attr % 100) ) if n <= 999: print(transfer(n)) elif 1000 <= n <= 999999: print(transfer(n // 1000) + " thousand " + transfer(n % 1000)) else: print( transfer(n // 1000000) + " million " + transfer((n % 1000000) // 1000) + " thousand " + transfer((n % 1000000) % 1000) )
一起讨论啊