-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.py
More file actions
39 lines (36 loc) · 851 Bytes
/
hello.py
File metadata and controls
39 lines (36 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# print("Hello world!")
# for i in range(1, 10):
# print(i)
def trim(s):
l = len(s)
if l == 0:
return ''
else:
x = y = 0
for i in range(l):
if s[i] != ' ':
x = i
break
for j in range((l - 1), -1, -1):
if s[j] != ' ':
y = j + 1
break
if x == y:
return ''
else:
return s[x:y]
# 测试:
if trim('hello ') != 'hello':
print('测试失败!')
elif trim(' hello') != 'hello':
print('测试失败!')
elif trim(' hello ') != 'hello':
print('测试失败!')
elif trim(' hello world ') != 'hello world':
print('测试失败!')
elif trim('') != '':
print('测试失败!')
elif trim(' ') != '':
print('测试失败!')
else:
print('测试成功!')