这个项目实在写不出来,初学者,还没有实战过,这是第一次项目实践,求能解答.
import re
print("---------欢迎来到字符串分诊系统------------\n"
"请选择需要的医疗服务\n"
"1:字符串分割\n"
"2:字母小写变大写\n"
"3:字母大写变小写\n"
"4:字符串取出所有的数字")
while 1:
try:
choose = int(input("请选择:"))
if choose not in [1, 2, 3, 4]:
print("输入错误,请重新输入!")
else:
break
except:
print("输入异常,请重新输入!")
if 1 == choose:
print("您选择[字符串分割]服务")
inputStr = input("请输入字符串:")
sep = input("请输入分割符:")
print(inputStr.split(sep))
elif 2 == choose:
print("您选择[字母小写变大写]服务")
inputStr = input("请输入字符串:")
print(inputStr.upper())
elif 3 == choose:
print("您选择[字母大写变小写]服务")
inputStr = input("请输入字符串:")
print(inputStr.lower())
elif 4 == choose:
print("您选择[字符串取出所有的数字]服务")
inputStr = input("请输入字符串:")
numList = re.findall(r'\d', inputStr)
print("".join(numList))
你是大佬
菜单用Print显示即可
然后等待键盘输入,输入的【1234】保存起来
然后输入一个字符串
然后对它进行手术,根据输入的【1234】调用不同的函数,输出结果后重新调用菜单或退出
1.大小写转换
S="asdfJKL123"
S.lower()
S.upper()
分割
S.split(sep=None, maxsplit=-1)
S.rsplit(sep=None, maxsplit=-1)
S.splitlines([keepends=True])
# sep为单个字符时
>>> '1,2,3'.split(',')
['1', '2', '3']
>>> '1,2,3'.split(',',1)
['1', '2,3'] # 只分割了一次
>>> '1,2,,3'.split(',')
['1', '2', '', '3'] # 不会压缩连续的分隔符
>>> '<hello><><world>'.split('<')
['', 'hello>', '>', 'world>']
# sep为多个字符时
>>> '<hello><><world>'.split('<>')
['<hello>', '<world>']
# 不指定sep时
>>> '1 2 3'.split()
['1', '2', '3']
>>> '1 2 3'.split(maxsplit=1)
['1', '2 3']
>>> ' 1 2 3 '.split()
['1', '2', '3']
>>> ' 1 2 3 \n'.split()
['1', '2', '3']
# 显式指定sep为空格、制表符、换行符时
>>> ' 1 2 3 \n'.split(' ')
['', '1', '', '2', '', '3', '', '\n']
>>> ' 1 2 3 \n'.split('\t')
[' 1 2 3 \n']
>>> ' 1 2\n3 \n'.split('\n')
[' 1 2', '3 ', ''] # 注意列表的最后一项''
>>> ''.split('\n')
['']
移除:strip、lstrip和rstrip
S.strip([chars])
S.lstrip([chars])
S.rstrip([chars])
#移除数字
S.strip('1234567890')
s = [ '请选择需要的服务',
'1:字符串分割',
'2:字母小写变大写',
'3:字母大写变小写',
'4:去除所有数字',
'欢迎来到字符串分诊系统']
print(f"{'-'*15}{s[-1]}{'-'*15}")
for i in s[:-1]:
print(i)
n = int(input())
if n==1:
s1 = input()
s2 = input()
print(s1.split(s2))
elif n==2:
s1 = input()
print(s1.upper())
elif n==3:
s1 = input()
print(s1.lower())
elif n==4:
s1 = input()
for i in range(10):
s1 = s1.replace(str(i),'')
print(s1)
print("""------------欢迎来到字符串分诊系统------------
请选择需要的服务
1:字符串分割,
2:字母小写变大写,
3:字母大写变小写,
4:去除所有数字,
""")
while 1:
n = int(input("请选择:"))
if n == 1:
s = input("请输入分割字符串:")
sep = input("请输入分割符:")
print(s.split(sep))
if n == 2:
s = input("请输入字符串:")
print(s.upper())
if n == 3:
s = input("请输入字符串:")
print(s.lower())
if n == 4:
s = input("请输入字符串:")
copy_s = s
for i in s:
if i.isdigit():
copy_s = copy_s.replace(i, '')
print(copy_s)
题主你试试这个,有问题欢迎提问,如果有帮到你,可以给个采纳吗