小编Den*_*ise的帖子

Python-尝试将列表中的项目相乘

所以基本上我在这里要做的是询问用户输入随机字符串,例如:

asdf34fh2
Run Code Online (Sandbox Code Playgroud)

而且我想把它们中的数字拉到一个列表中然后得到[3,4,2]但是我一直在接受[34, 2].

import re 

def digit_product():        
    str1 = input("Enter a string with numbers: ")

    if str1.isalpha():
        print('Not a string with numbers')
        str1 = input("Enter a string with numbers: ")
    else:
        print(re.findall(r'\d+', str1))   

digit_product()      
Run Code Online (Sandbox Code Playgroud)

然后我想拿出那个数字列表并乘以它们,最终得到24.

python python-3.x python-3.4

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

标签 统计

python ×1

python-3.4 ×1

python-3.x ×1