In [5]:
#自己定义一个reverse(s)函数,功能返回字符串s的倒序字符串。
def reverse(s):
print(s[(len(s)):0:-1]+s[0])
s = str(input('请输入字符串,以回车结尾:'))
reverse(s)
In [1]:
#写函数,根据给定符号和行数,打印相应直角三角形,等腰三角形及其他形式的三角形。
def triangle(s,n):
if s == 'right':
for i in range(0,n):
if n == (i+1):
print('|' + '_'*i + '\\',end='')
else:
print('|' + ' '*i + '\\')
if s == 'isosceles':
for i in range(0,n+1):
if n == (i+1):
print(' '*(n-i) + '/' + '_'*(2*i) + '\\',end='')
else:
print(' '*(n-i) + '/' + ' '*(2*i) + '\\')
s = str(input('请输入符号:'))
n = int(input('请输入行数:'))
triangle(s,n)
In [4]:
#将任务4中的英语名词单数变复数的函数,尽可能的考虑多种情况,重新进行实现。
def word(m):
if m.endswith('s') or m.endswith('x') or m.endswith('z') or m.endswith('ch') or m.endswith('sh'):
print(m[0:len(m) + 'es'])
elif m.endswith('y'):
print(m[0:(len(m)-1)] + 'es')
elif m.endswith('f'):
print(m[0:(len(m)-1)] + 'ves')
elif m.endswith('fe'):
print(m[0:(len(m)-2)] + 'ves')
else:
print(m[0:len(m)] + 's')
m = str(input('请输入要输入的英文单词,回车结束。'))
word(m)