python字符串大小写和函数参数的问题
大家好,我是新手请多多关照。求教一个问题:我想用函数 get_string()来接收用户输入的字符串然后作为参数传送给函数capitalize_it(x),再通过capitalize_it(x)将字符串中某些字母大写,如".", "?", "!"后面单词的首字母和单独的i大写(不是每个单词首字母都大写)效果如下:
输入
Hi everyone!my name is xxx.please to meet you all.i'm a novice and i appreciate any help.thank you.
输出
Hi everyone!My name is xxx.Please to meet you all.I'm a novice and I appreciate any help.Thank you.
下面是部分代码:
#接收用户输入(为使代码尽量简单故未过滤输入)
def get_string()
string = input("Please enter a string:")
return string
#将字符串符合条件的字母变成大写
def capitalize_it(x)
for i in range(0,len(x)):
if x[i] == " " or x[i] == "." or x[i] == "?" or x[i] == "!"
x[i+1].upper()
print(x)
#call capitalize_it(x)
capitalize_it(get_string())
#我试过多种方法但都没有用。求指点,拜谢