5-2:
str1
=
"wo hen kai xin"
str2
=
"wo bu kai xin"
print(
str
!= str2)
test1
=
"JaiR"
test2
=
"jair"
print(test1.lower()
== test2)
num1
=
10000
num2
=
1238522
print(num1
== num2, num1
!= num2, num1
> num2, num1
< num2, num1
<= num2, num1
>= num2)
age1
=
19
age2
=
11
print(age1
>
18
and age2
>
18, age1
>
18
or age2
>
18)
users
= [
'andrew',
'carolina',
'david']
print(
'andrew'
in users)
print(
'jay'
not
in users)
5-3
alien_color
=
'green'
if alien_color
==
'green':
print(
"you get five points")
alien_color
=
'red'
if alien_color
==
'green':
print(
"you get five points")
5-4
alien_color
=
'green'
if alien_color
==
'green':
print(
"you get five points")
else:
print(
'you get ten points')
alien_color
=
'red'
if alien_color
==
'green':
print(
"you get five points")
else:
print(
'you get ten points')
5-5
alien_color
=
'green'
if alien_color
==
'green':
print(
"you get five points")
elif alien_color
==
'yellow':
print(
'you get ten points')
elif alien_color
==
'red':
print(
'you get fifteen points')
alien_color
=
'red'
if alien_color
==
'green':
print(
"you get five points")
elif alien_color
==
'yellow':
print(
'you get ten points')
elif alien_color
==
'red':
print(
'you get fifteen points')
alien_color
=
'yellow'
if alien_color
==
'green':
print(
"you get five points")
elif alien_color
==
'yellow':
print(
'you get ten points')
elif alien_color
==
'red':
print(
'you get fifteen points')
5-6
for age
in
range(
1,
100):
if age
<
2:
print(
'he is a baby')
elif
2
<= age
<
4:
print(
'he is leaning walking')
elif
4
<= age
<
13:
print(
'he is a child')
elif
13
<= age
<
20:
print(
'he is a teenager')
elif
20
<= age
<
65:
print(
'he is an adult')
elif age
>=
65:
print(
'he is an old man')
5-7:
favorite_fruits
= [
'banana',
'apple',
'pineapple',
'orange']
if
'mangosteen'
in favorite_fruits:
print(
'you really like mangosteen')
if
'banana'
in favorite_fruits:
print(
'you really like banana')
if
'apple'
in favorite_fruits:
print(
'you really like apple')
if
'pineapple'
in favorite_fruits:
print(
'you really like pineapple')
if
'orange'
in favorite_fruits:
print(
'you really like orange')
5-8:
users
= [
'admin',
'John',
'Eric',
'Alan',
'James']
for user
in users:
if user
==
'admin':
print(
"Hello admin, would you like to see a status report?")
else:
print(
'hello', user,
'thank you for logging in again')
5-9:
users
= [
'admin',
'John',
'Eric',
'Alan',
'James']
if users:
for user
in users:
if user
==
'admin':
print(
"Hello admin, would you like to see a status report?")
else:
print(
'hello', user,
'thank you for logging in again')
else:
print(
'We need to find some users!')
users.clear()
if users:
for user
in users:
if user
==
'admin':
print(
"Hello admin, would you like to see a status report?")
else:
print(
'hello', user,
'thank you for logging in again')
else:
print(
'We need to find some users!')
5-10:
current_users
= [
'John',
'Eric',
'Alan',
'James',
'Mary']
new_users
= [
'James',
'John',
'Jair',
'Jay',
'Alex',
'mary']
for user
in new_users:
if user.lower()
in [current.lower()
for current
in current_users]:
print(
'you need to input another name')
else:
print(user,
"isn't used")
5-11:
lists
= [num
for num
in
range(
1,
10)]
for item
in lists:
if item
==
1:
print(
'1st')
elif item
==
2:
print(
'2nd')
elif item
==
3:
print(
'3rd')
else:
print(
str(item)
+
'st')