Discuss / Python / 交作业

交作业

Topic source

IE洗铁路

#1 Created at ... [Delete] [Delete and Lock User]

# -*- coding: utf-8 -*-

def product(*numbers):

    pro = 1

    for n in numbers:

      pro = pro * n

    return pro

numb = input ('numbers=')

i = product(*numb)

print(i)

小凤三_632

#2 Created at ... [Delete] [Delete and Lock User]

input传入的数据是字符串,不是列表

小凤三_632

#3 Created at ... [Delete] [Delete and Lock User]

字符串也可以作为可变参数传入吗?

小凤三_632

#4 Created at ... [Delete] [Delete and Lock User]

试了一下倒是真行,但两位数以上的数字你这串代码就不行了

小凤三_632

#5 Created at ... [Delete] [Delete and Lock User]

假定输入的时候以逗号间隔,那么可以这样改写一下:numb = input(‘numbers = ‘).split(‘,’)


  • 1

Reply