1.name = "aleX leNb"
1.a = name.strip()
print(a)
2.a = name.lstrip('al')
print(a)
3.a = name.rstrip('Nb')
print(a)
4.a = name.lstrip('a')
b = a.rstrip("b")
print(b)
5.print(name.startswith('al'))
6.print(name.endswith('Nb'))
7.a = name.replace('l','p')
print(a)
8.a = name.replace('l','p',1)
print(a)
9.a = name.split('l')
print(a)
10.a = name.split('l',1)
print(a)
11.a = name.upper()
print(a)
12.a = name.lower()
print(a)
13.(1)s1 = name[:1]
s2 = name[1:]
print(s1.upper() + s2)
(2)name.replace('a','A',1)
14.count = name.count('l')
print(count)
15.s1 = name[:4]
s2 = s1.count('l')
print(s2)
16.s1 = name.index('N')
print(s1)
17.s1 = name.find('N')
print(s1)
18.s1 = name.find('X le')
print(s1)
19.s1 = name[2]
print(s1)
20.s1 = name[:3]
print(s1)
21.s1 = name[-2:]
print(s1)
22.count = 0
while count < len(name):
if name[count] == 'e':
print(count)
count += 1
2.s = "123a4b5c"
1.s1 = s[:3]
print(s1)
2.s1 = s[3:6]
print(s1)
3.s1 = s[::2]
print(s1)
4.s1 = s[1:6:2]
print(s1)
5.s1 = s[-1]
print(s1)
6.s1 = s[-3:-8:-2]
print(s1)
3.count = 0
while count < len(s):
print(s[count])
count += 1
for a in s:
print(a)
4.for c in s:
print(s)
5.for a in s:
print(a + 'sb')
6.for a in s:
print('倒计时' + a + '秒') #print('倒计时%c秒'% a)
else:
print('出发!')
7.两数相加:
num = input("请输入算式:")
s = num.split('+')
s1 = int(s[0])
s2 = int(s[1])
print(s1 + s2)
8.多数相加:
num = input("请输入算式:")
s = num.split('+')
count = 0
a = 0
while count < len(s):
a = a + int(s[count])
count += 1
print(a)
9.内容中几个整数:
(1)num = input("请输入内容:")
count = 0
a = 0
while count < len(num):
if num[count].isdigit():
a += 1
count +=1
print(a)
(2)num = input("请输入内容:")
count = 0
for a in num:
if a.isdigit():
count += 1
print(count)
10.回家方式:
while 1:
num = input("请输入ABC:").strip().upper()
if num == 'A':
print('走大路回家')
num2 = input('公交车还是步行?')
if num2 == '公交车':
print('10分钟到家.')
break
else:
print('20分钟到家.')
break
if num == 'B':
print('走小路回家.')
break
if num == 'C':
print('绕道回家.')
num3 = input("游戏厅还是网吧?")
if num3 == "游戏厅":
print('一个半小时到家,挨打,重新输入:')
else:
print('两小时到家,挨打,重新输入:')
11.1-2+3-4...+99:
(1)a = 1
b = 2
s1 = 0
s2 = 0
while a < 100:
s1 = s1 + a
a += 2
while b < 99:
s2 = s2 + b
b += 2
print(s1-s2+88)
(2)a = 1
s = 0
while a < 100:
if a%2 == 0:
s = s - a
else:
s = s + a
a +=1
print(s+88)
12.回文:
s = input('输入一句话:')
s1 = s[::-1]
if s == s1:
print('是')
else:
print('否')
13.一句话各种字符的个数:
s = input('输入一句话:')
daxie = 0
xiaoxie = 0
shuzi = 0
other = 0
for c in s:
if c.isdigit():
shuzi +=1
elif c.isupper():
daxie +=1
elif c.islower():
xiaoxie +=1
else:
other +=1
print(daxie,xiaoxie,shuzi,other)
14.格式化输出;
a1 = input('请输入姓名:')
a2 = input('请输入地点:')
a3 = input('请输入爱好:')
print('可爱的{a1}喜欢在{a2}{a3}'.format( a1 = a1 ,a2 = a2 , a3=a3))
15.姓氏是否在百家姓:
s = input('请输入姓名:')
s1 = ''
bjx = '赵钱孙李周吴郑王'
for c in s:
s1 = s1 + c
if s1 in bjx:
print('是')
break
else:
print('否')
break
16.
s = input('请输入内容:')
a = 0
while a < len(s):
print(s[a])
a += 1
s = input('请输入内容:')
for c in s :
print(c)