python怎么将输入的数字变成列表,如何在Python中将用户数字输入收集到列表中?...

I'm new to Python and am trying to make a simple program to calculate mean median and mode from numbers input by user. So far I have:

num=[]

UserNumbers=int(input("Enter number sequence separated by spaces: "))

num.append(UserNumbers)

print (num)

I want the user to be able to input multiple int's separated by spaces, however my code only accepts one number. The mean/median/mode part shouldn't be hard as I'm just going to use statistics package in 3.4; just need help with gathering input.

解决方案

You have to parse the answer if you want it this way.

UserNumbers=input("Enter number sequence separated by spaces: ")

nums = [int(i) for i in UserNumbers.split()]

EDIT:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值