第五章

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')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值