字符串的分段組合問題
問題:
用戶輸入一個字符串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()方法