该程序通过两种方式来实现字母的翻转,一种是通过普通方式,另一种是通过自定义函数的方式来实现,该程序还对用户的输入可靠性进行判断,用户输入的必须是字母,如果输入数字,python程序会提示用户输入错误,让用户重新输入。
该程序实现的核心功能如:python -----> PYTHON
该程序的代码如下:
普通方式:
\编写程序,实现对输入字符串的大小写字母翻转(即大写变小写、小写变大写)操作。\while True:user_string = input("Please input the string: ")//捕获用户输入的信息collect_string = [] //创造空列表用来存放转换后的字母if user_string.isalpha(): //判断用户输入的是否是字母for i in user_string: //用for循环读取用户输入的信息if i.islower(): //判断是否是小写字母collect_string.append(i.upper()) //如果是小写字母,先执行upper函数,将小写转化为大写,然后用列表的append方法追加到列表里else:collect_string.append(i.lower())//如果是大写字母,先执行lower函数,将大写转化为小写,然后用列表的append方法追加到列表里result_string = "".join(collec