字符串的分段组合问题
问题:
用户输入一个字符串s,以字符减号(+)分割s,将其中的首尾段用加号(-)组合输出
如表输入输出:
输入 | 输出 |
---|---|
Learning+python+is+a+great+choice | Leaning-choice |
1+2+3+4+5+6+7+8 | 1-8 |
s = input();
str = s.split("+")
print("{}-{}".format(str[0],str[-1]))
涉及知识点:split()方法,format()方法
用户输入一个字符串s,以字符减号(+)分割s,将其中的首尾段用加号(-)组合输出
输入 | 输出 |
---|---|
Learning+python+is+a+great+choice | Leaning-choice |
1+2+3+4+5+6+7+8 | 1-8 |
s = input();
str = s.split("+")
print("{}-{}".format(str[0],str[-1]))
涉及知识点:split()方法,format()方法