In [1]:
#exercise 1
def reverse (s):
print(s[len(s)-1::-1])
s=str(input("plz enter a string"))
reverse(s)
In [2]:
#exercise 2
def triangle (x):
for i in range (x):
if i<x-1:
print('|'+' '*i+'\\')
elif i==x-1: print('|'+'_'*i+'\\')
print(' ')
for i in range (x):
if i<x-1:
print(' '*(x-i)+'/'+' '*(2*i)+'\\')
elif i==x-1:
print(' '+'/'+'_'*(i+x-1)+'\\')
x=int(input("plz enter the height of the triangle\n"))
triangle(x)
In [3]:
#exercise 3
def change(word):
print('The plurality of the noun is ',end='')
if word.endswith('ch') or word.endswith('sh'):
print(word+'es')
elif word.endswith('x') or word.endswith('s') or word.endswith('es'):
print(word+'es')
elif word.endswith('f'):
print(word[:len(word)-1:]+'ves')
elif word.endswith('y'):
print(word[:len(word)-1:]+'ies')
else: print(word+'s')
word=str(input("plz enter a countable noun\n"))
change(word)
In [10]:
#exercise 4
def tixing(a,b,c,d):
if b<=c:
k=(c-b)//(d-1)
for i in range(d):
print(b*a+k*a*i)
else:
k=k=(b-c)//(d-1)
for i in range(d):
print((b-k*i)*a)
x=input('请输入给定符号')
A=int(input('请输入上底长度'))
B=int(input('请输入下底长度'))
h=int(input('请输入高度'))
tixing(x,A,B,h)
In [5]:
#exercise 5
def rhombus (x):
for i in range (x):
print(' '*(x-i)+'/'+' '*(2*i)+'\\')
for i in range(x-1,-1,-1):
print(' '*(x-i)+'\\'+' '*(2*(i))+'/')
x=int(input('请输入菱形的边长 '))
rhombus(x)
In [6]:
#exercise 6
def inverted(x):
for i in range(len(x)*2,0,-1):
if i == 1:
print(' '*(len(x)*2-1) +x[0])
elif i%2 == 1:
print(' '*(len(x)*2-i) + x[:i//2] + x[i//2] + x[i//2-1::-1])
else:
print(' '*(len(x)*2-i) + x[:i//2] + x[i//2-1::-1])
def main():
word = '赏花归去马如飞'
inverted (word)
if __name__ == '__main__':
main()
In [ ]: