python输入一个值_在Python中处理多个输入值

当然!你必须提供某种"标记"但是,当你完成的时候。怎么样:

if num == '1':

lst_of_nums = []

while True: # infinite loops are good for "do this until I say not to" things

new_num = raw_input("Enter value: ")

if not new_num.isdigit():

break

# if the input is anything other than a number, break out of the loop

# this allows for things like the empty string as well as "END" etc

else:

lst_of_nums.append(float(new_num))

# otherwise, add it to the list.

results = []

for num in lst_of_nums:

results.append(num/1e4)

# this is more tersely communicated as:

# results = [num/1e4 for num in lst_of_nums]

# but list comprehensions may still be beyond you.

如果您尝试输入一串以逗号分隔的值,请尝试:

numbers_in = raw_input("Enter values, separated by commas\n>> ")

results = [float(num)/1e4 for num in numbers_in.split(',')]

如果你想列出这两个,那么,构建一个字典!

numbers_in = raw_input("Enter values, separated by commas\n>> ")

results = {float(num):float(num)/1e4 for num in numbers_in.split(',')}

for CGS,SI in results.items():

print "%.5f = %.5fT" % (CGS, SI)

# replaced in later versions of python with:

# print("{} = {}T".format(CGS,SI))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值