我被困在简单的事情,但我不能睡好,直到我要解决这个问题。你知道吗
所以我的想法是:
挑战:
例如,如果我使用append创建一个输入列表,那么在求和时我收到:
k = sum(args) #works if list of (rgs can be readed as ints or strs TypeError: unsupported operand type(s) for +: 'int' and 'str'
一些代码:
def autosum(*args):
k = sum(args) #works if list of (rgs can be readed as ints or strs
print "Your sum", k
return
print ("Type integer or x to close")
input_list = list()
while True:
rawinputvalue = raw_input(">>")
input_list = rawinputvalue
if type(rawinputvalue) != "x":
break
input_list.append(rawinputvalue)
autosum(input_list)
这些是如何使用不同类型的参数以及函数的一些用法的基础知识。希望其他人也能从中吸取教训,谢谢。 唐
目前没有回答
相关问题 更多 >
编程相关推荐