Python-day 8-文字列の宿題を勝手に書きます
18581 ワード
str1 = 'abcd1234'
print(str1[1::2])
user_name = input(' :')
if 6 <= len(user_name) <= 10:
print(' !')
else:
print(' !')
user_name = input(' :')
for x in user_name:
if '0' <= x <= '9' or ('a' <= x <= 'z' or 'A' <= x <= 'Z'):
continue
else:
print(' !')
break
else:
print(' !')
user_name = input(' :')
for x in user_name:
if 'A' <= user_name[0] <= 'Z':
if '0' <= x <= '9' or ('a' <= x <= 'z' or 'A' <= x <= 'Z'):
continue
else:
print(' !')
break
else:
print(' !')
str2 = 'abc1shj23kls99+2kkk'
str3 = ''.join([x for x in str2 if '0' <= x <= '9'])
print(str3)
str4 = 'a2h2klm12+'
print(str4.upper())
str5 = []
for x in str4:
if 'a' <= x <= 'z':
x = chr(ord(x) - 32)
str5.append(x)
else:
str5.append(x)
print(''.join(str5))
str_num = 'py1901'
num = input(' 1000 :')
if int(num) < 100:
str_num = str_num + num.zfill(3)
else:
str_num = str_num + num
print(str_num)
str6 = input(' :')
count = 0
for x in str6:
if '0' <= x <= '9' or ('a' <= x <= 'z' or 'A' <= x <= 'Z'):
continue
else:
count += 1
print(count)
str7 = input(' :')
new_str7 = []
for x in str7:
if x == str7[0] or x == str7[-1]:
x = '+'
new_str7 += x
print(''.join(new_str7))
str8 = input(' :')
if len(str8) & 1 == 0:
print(str8[len(str8) // 2 -1], str8[len(str8) // 2])
else:
print(str8[len(str8) // 2])
str9 = 'how are you? Im fine, Thank you!'
str10 = 'you'
for x in range(len(str9)):
if str9[x] == str10[0]:
if str9[x+1] == str10[1]:
if str9[x+2] == str10[2]:
print(x)
break
たとえば、文字列1はabc 123、文字列2はhuak 3、印刷:共通文字はa 3
str11 = 'abc123'
str12 = 'huak3'
str13 = []
for x in str11:
for y in str12:
if x == y:
str13.append(y)
print(''.join(str13))