'''
輸入一個(gè)字符串,打印所有奇數(shù)位上的字符(下標(biāo)是1外傅,3纪吮,5,7…位上的字符)
a = input('請輸入:')
print(a[::2])
輸入用戶名萎胰,判斷用戶名是否合法(用戶名長度6~10位)
while True:
a = input('請輸入:')
b = 0
for i in a:
b += 1
if 6<=b<=10:
print('名字合法')
break
else:
print('名字不合法')
'''
'''
輸入用戶名碾盟,判斷用戶名是否合法(用戶名中只能由數(shù)字和字母組成)
48-57 65-90 97-122
例如: 'abc' — 合法 '123' — 合法 ‘a(chǎn)bc123a’ — 合法
'''
a = input('請輸入:')
for i in a:
if not('a'<=i<='z'or'0'<=i<='9'or 'A'<= i<='Z'):
print('非法名')
break
else:
print('he法名')
'''
輸入用戶名,判斷用戶名是否合法(用戶名必須包含且只能包含數(shù)字和字母技竟,并且第一個(gè)字符必須是大寫字母)
例如: 'abc' — 不合法 '123' — 不合法 'abc123' — 不合法 'Abc123ahs' — 合法
while True:
a = input('請輸入:')
if 'A'<= a[0]<='Z':
for i in a:
if not('a'<=i<='z'or'0'<=i<='9'or 'A'<= i<='Z'):
print('非法名')
break
else:
print('合法名')
break
else:
print('非法名')
'''輸入一個(gè)字符串冰肴,將字符串中所有的數(shù)字字符取出來產(chǎn)生一個(gè)新的字符串
例如:輸入'abc1shj23kls99+2kkk' 輸出:'123992'
a = input('請輸入:')
for i in a:
if '0'<=i<='9':
print(i,end=(''))
'''輸入一個(gè)字符串,將字符串中所有的小寫字母變成對應(yīng)的大寫字母輸出
例如: 輸入'a2h2klm12+' 輸出 'A2H2KLM12+'
a = input('請輸入:')
for i in a:
if 'a'<=i<='z':
print(chr(ord(i)-32),end=(''))
else:
print(i,end='')
'''輸入一個(gè)小于1000的數(shù)字榔组,產(chǎn)生對應(yīng)的學(xué)號
例如: 輸入'23'熙尉,輸出'py1901023' 輸入'9', 輸出'py1901009' 輸入'123',輸出'py1901123'
a = input('請輸入:')
print('py1901',end=(''))
print(a.rjust(3, '0'))
輸入一個(gè)字符串搓扯,統(tǒng)計(jì)字符串中非數(shù)字字母的字符的個(gè)數(shù)
例如: 輸入'anc2+93-sj胡說' 輸出:4 輸入'===' 輸出:3
b = 0
a = input('請輸入:')
for i in a:
if not(('0'< i<'9')and('a'<i<'z')and('A'<i<'Z')):
b += 1
print(b)
輸入字符串检痰,將字符串的開頭和結(jié)尾變成'+',產(chǎn)生一個(gè)新的字符串
例如: 輸入字符串'abc123', 輸出'+bc12+'
b = 0
a = input('請輸入:')
for i in a:
b += 1
print('+',end=(''))
print(a[1:-1:1],end=(''))
print('+')