【HW】第五章作业 2018.3.19

Python代码:

#Chapter 5 by szh 2018.3.19
print("\n5.2")
print("student" == "Student")
print("student" == "Student".lower())
print(12 == 12)
print(12 != 13)
print(12 >= 13)
print(12 < 13 and 13 > 14)
print(12 > 13 or 12 < 13)
nums = [1, 2, 3, 4, 5]
print(3 in nums)
print(6 not in nums)

print("\n5.3")
alien_color = 'green'
if alien_color == 'green':
    print("You got 5 points!")

print("\n5.4")
alien_color = 'yellow'
if alien_color == 'green':
    print("You got 5 points!")
else:
    print("You got 10 points!")

print("\n5.5")
alien_color = 'red'
if alien_color == 'green':
    print("You got 5 points!")
elif alien_color == 'yellow':
    print("You got 10 points!")
else:
    print("You got 15 points!")

print("\n5.6")
ages = [1, 3, 10, 18, 40, 70]
for age in ages:
    if age < 2:
        print("He is a baby.")
    elif age < 4:
        print("He is learn to walk.")
    elif age < 13:
        print("He is a children.")
    elif age < 20:
        print("He is a teenager.")
    elif age < 65:
        print("He is a adult.")
    else:
        print("He is a elder.")

print("\n5.7")
favorite_fruits = ['apple', 'banana', 'watermelon']
question_fruits = ['apple', 'banana', 'watermelon', 'orange', 'kiwi']
for fruit in question_fruits:
    if fruit in favorite_fruits:
        print("You really like " + fruit)
    else:
        print("You don't like the " + fruit)

print("\n5.8")
names = ['admin', 'Alice', 'Bob', 'Eric', 'Jack']
for name in names:
    if name == 'admin':
        print("Hello admin, would you like to see a status report?")
    else:
        print("Hello " + name + ", thank you for logging in again")


输出结果:

5.2
False
True
True
True
False
False
True
True
True

5.3
You got 5 points!

5.4
You got 10 points!

5.5
You got 15 points!

5.6
He is a baby.
He is learn to walk.
He is a children.
He is a teenager.
He is a adult.
He is a elder.

5.7
You really like apple
You really like banana
You really like watermelon
You don't like the orange
You don't like the kiwi

5.8
Hello admin, would you like to see a status report?
Hello Alice, thank you for logging in again
Hello Bob, thank you for logging in again
Hello Eric, thank you for logging in again
Hello Jack, thank you for logging in again



猜你喜欢

转载自blog.csdn.net/empire_03/article/details/79616874