相关疑难解决方法(0)

有没有办法将数字转换为整数?

我需要转换one1,two转入2等等.

有没有办法用库或类或任何东西来做到这一点?

python string text integer numbers

61
推荐指数
7
解决办法
6万
查看次数

代码高尔夫:数字到单词

代码高尔夫系列似乎相当受欢迎.我遇到了一些将数字转换为单词表示的代码.一些例子是(编程乐趣的2的权力):

  • 2 - >两个
  • 1024 - >一千二十四
  • 1048576 - >百万四万八千七百六十六

我的同事出现的算法差不多有两百行.似乎会有更简洁的方法来做到这一点.

现行指南:

  • 以任何编程语言欢迎提交的内容(我向PhiLho道歉,因为最初对此不太清楚)
  • 最大输入为2 ^ 64(请参阅以下链接,感谢mmeyers)
  • 英语输出的缩放比例较低,但欢迎使用任何算法.只需对编程语言一起评论所使用的方法.

language-agnostic nlp code-golf rosetta-stone

39
推荐指数
13
解决办法
1万
查看次数

如何在Python中将整数转换为英文表示?

我需要将整数转换为python中的英文(字符串)表示.例:

5 = five
20 = twenty
etc.
Run Code Online (Sandbox Code Playgroud)

我知道,我可以使用条件,但我需要转换许多整数,所以我需要以最快的方式来实现它.

python string integer

1
推荐指数
1
解决办法
2391
查看次数

如何将整数转换为python中的单词?

编写一个以整数作为输入参数的函数,并使用单词返回整数.例如,如果输入是4721,那么函数应该返回字符串"four seven two one".请注意,单词之间应该只有一个空格,并且它们应该在您返回的字符串中全部小写.

这是我的代码:

def Numbers_To_Words (number):
    dict = {1: "one", 2: "two", 3: "three", 4: "four", 5: "five", 6: "six", 7: "seven", 8: "eight", 9: "nine", 0: "zero"}
    output_str = " "
    list = []

#Main Program
number = 4721
result = Numbers_To_Words (number)
print (result)
Run Code Online (Sandbox Code Playgroud)

我的问题是,如何将数字分开,然后与我创建的字典进行比较?我知道长度不适用于整数数据类型.我知道将密钥发送到字典并获取其各自值的进一步逻辑.但在此之前,我被困在这里分隔整数的数字.

python python-3.x

1
推荐指数
2
解决办法
4170
查看次数

将数字改为单词

可能重复:
如何告诉Python将整数转换为单词

我正在尝试编写一个简单的函数,它将输入作为整数,然后将其显示为单词.我不确定如何正确地说出这个问题.这是一个时钟应用程序,这就是我正在做的,但我相信有一个更简单的方法.

if h == 1: h = "One"
if h == 2: h = "Two"
if h == 3: h = "Three"
if h == 4: h = "Four"
if h == 5: h = "Five"
if h == 6: h = "Six"
if h == 7: h = "Seven"
if h == 8: h = "Eight"
if h == 9: h = "Nine"
if h == 10: h = "Ten"
if h == 11: h = "Eleven" …
Run Code Online (Sandbox Code Playgroud)

python integer

0
推荐指数
1
解决办法
160
查看次数

如何用Python打印任何单词?

如果不使用库函数,如何在Python中打印任意数量的单词?有一些答案是使用库函数,但我想要核心代码.

Like:
    12345 = "twelve thousand three hundred and forty five"
    97835200 ="Nine core seventy eight lakh thirty five thousand two hundred"
    230100 = "Two lakh thirty thousand one hundred"
Run Code Online (Sandbox Code Playgroud)

python python-2.7

0
推荐指数
1
解决办法
1497
查看次数