python3.6 输入多行,输出多行

要求输入多行,如

3 97 98 99

4 97 98 99 100

输出多行,如

98.00

98.50

代码:

import sys
result=[]
for line in sys.stdin:
    if line[0] is '\n':
        break
    score = line.split()
    score=list(map(int,score))
    n=score[0]
    score=score[1:]
    scoresum=sum(score)-min(score)-max(score)
    sc=float(scoresum)/(n-2)
    result.append(round(sc,2))
for i in result:
    print(format(i,'.2f'))

 

结果:

3 97 98 99
4 97 98 99 100

98.00
98.50

 

Python中合并多行通常是指将多个字符串变量合并成一个字符串。这可以通过多种方式实现,例如使用加号(+)连接,使用join()方法,或者使用字符串格式化方法。下面分别介绍这三种常见的方法: 1. 使用加号(+)连接: 可以直接使用加号将多个字符串连接起来,生成一个新的字符串。如果需要换行,可以在字符串中包含换行符`\n`。 示例代码: ```python str1 = "Hello, " str2 = "World!\n" str3 = str1 + str2 print(str3) ``` 2. 使用join()方法: 如果有多个字符串需要合并,并且这些字符串分别存储在一个列表中,可以使用join()方法。这个方法会将列表中的所有字符串元素合并成一个字符串,并且可以指定一个分隔符。 示例代码: ```python strings = ["Hello, ", "World!\n", "Python "] combined = "".join(strings) print(combined) ``` 3. 使用字符串格式化方法: 字符串格式化是一种更加灵活的合并字符串的方式,可以使用不同的格式化方法如`%`操作符、`str.format()`方法或f-string(Python 3.6+)。 示例代码使用`%`操作符: ```python str1 = "Hello, " str2 = "World!" combined = "%s%s\n" % (str1, str2) print(combined) ``` 示例代码使用`str.format()`方法: ```python str1 = "Hello, " str2 = "World!" combined = "{}{}\n".format(str1, str2) print(combined) ``` 示例代码使用f-string: ```python str1 = "Hello, " str2 = "World!" combined = f"{str1}{str2}\n" print(combined) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值