#-*-coding:utf-8 -*-
#5-1
superhero
=
'spider-man'
print
(
'is superhero == spider-man?'
,
'i predict true'
)
print
(superhero
==
'spider-man'
)
print
(
'is superhero == batman?'
,
'i predict false'
)
print
(superhero
==
'batman'
)
food
=
'apple'
print
(
'is food == apple?'
,
'i predict true'
)
print
(food
==
'apple'
)
print
(
'is food == banana ?'
,
'i predict false'
)
print
(food
==
'banana'
)
game
=
'gtav'
print
(
'is game == gtav?'
,
'i predict true'
)
print
(game
==
'gtav'
)
print
(
'is game == sleeping dog?'
,
'i predict false'
)
print
(game
==
'sleeping dog'
)
#5-2
print
(
'pizza'
==
'pizza'
)
print
(
'pizza'
==
'banana'
)
print
(
'APPLE'
.lower()
==
'apple'
)
print
(
'BANANA'
.lower()
==
'apple'
)
print
(
5
==
5
)
print
(
4
==
3
)
print
(
100
>
9
)
print
(
100
>
200
)
print
(
100
>=
100
)
print
(
34234
>=
234123412
)
print
(
7
<
6
)
print
(
7
<
10
)
print
(
7
<=
7
)
print
(
7
<=
6
)
print
(
5
!=
5
)
print
(
6
!=
10
)
print
(
100
>
200
and
100
<
200
)
print
(
513
>=
223
and
'apple'
==
'Apple'
.lower())
print
(
345
==
566
or
'3'
==
'3'
)
print
(
23123
<=
23123456
or
'l'
in
'feet'
)
print
(
'aaaa'
in
[
'aaaa'
,
'bbbb'
,
'cccc'
])
print
(
'abcd'
in
[
'piece'
,
'feet'
])
print
(
456
not
in
[
234
,
345
,
456
])
print
(
666
not
in
[
111
,
222
,
333
])
#5-3
alien_color
=
[
'green'
,
'yellow'
,
'red'
]
if
(
'green'
is
alien_color[
0
]):
print
(
'you get 5 scores !'
)
if
(
'blue'
is
alien_color[
2
]):
pass
#5-4
if
(
'green'
is
alien_color[
0
]):
print
(
'you will get 5 scores cause you shoot him'
)
else
:
print
(
'you get 10 scores !'
)
if
(
'green'
is
alien_color[
2
]):
print
(
'you will get 5 scores cause you shoot him'
)
else
:
print
(
'you get 10 scores !'
)
#5-5
#5-6
def
jud_age
(
age
):
if
age
<
2
:
print
(
'baby'
)
elif
age
>=
2
and
age
<
4
:
print
(
'learn how to walk'
)
elif
age
>=
4
and
age
<
13
:
print
(
'child'
)
elif
age
>=
13
and
age
<
20
:
print
(
'teenager'
)
elif
age
>=
20
and
age
<
65
:
print
(
'adult'
)
else
:
print
(
'old man'
)
#5-7
favorite_fruits
=
[
'pizza'
,
'beijing_duck'
,
'banana'
]
if
'apple'
not
in
favorite_fruits:
print
(
'sorry!'
)
else
:
print
(
'you really like banana'
)
if
'pizza'
not
in
favorite_fruits:
print
(
'sorry!'
)
else
:
print
(
'you really like pizza'
)
if
'shit'
not
in
favorite_fruits:
print
(
'sorry!'
)
else
:
print
(
'you really like shit'
)
if
'bread'
not
in
favorite_fruits:
print
(
'sorry!'
)
else
:
print
(
'you really like bread'
)
if
'beijing_duck'
not
in
favorite_fruits:
print
(
'sorry!'
)
else
:
print
(
'you really like beijing_duck'
)
#5-8
user
=
[
'admin'
,
'xiaojz'
,
'yangxh'
,
'yangxy'
,
'lr'
]
for
i
in
user:
if
i
==
'admin'
:
print
(
'hello admin , would you like to see a status report?'
)
else
:
print
(
'hello'
,i,
'thank you for logging in again'
)
#5-9
if
user:
for
i
in
user:
if
i
==
'admin'
:
print
(
'hello admin , would you like to see a status report?'
)
else
:
print
(
'hello'
,i,
'thank you for logging in again'
)
else
:
print
(
'We need to find some users!'
)
#5-10
def
L
(
s
):
return
str
(s).lower()
current_users
=
[
'John'
,
'jack'
,
'lee'
,
'hugh'
,
'kehan'
]
new_users
=
[
'JOHN'
,
'Jack'
,
'rick'
,
'mo'
,
'Hugh'
]
for
a
in
new_users:
if
a.lower()
in
map
(L,current_users):
print
(
'used!'
)
else
:
print
(
'not used!'
)
#5-11
number
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
]
for
i
in
number:
if
i
==
1
:
print
(
str
(i)
+
'st'
)
elif
i
==
2
:
print
(
str
(i)
+
'nd'
)
elif
i
==
3
:
print
(
str
(i)
+
'rd'
)
else
:
print
(
str
(i)
+
'th'
)
#5-12
#已经正确设置