标签:alt 用户登录 一个用户 class crash 练习 代码 婴儿 获得
car = ‘subaru‘
print("Is car == ‘subaru‘? I predict True.") print(car == ‘subaru‘)
print("\nIs car == ‘audi‘? I predict False.") print(car == ‘audi‘)
health = "great"
print("Is health == ‘great‘? I predict True.")
print(car == ‘great‘)
print("\nIs health == ‘bad‘? I predict False.")
print(car == ‘bad‘)
car = "Audi"
print("Is car ==‘BWM‘ I predict False.")
print(car == ‘BWM‘)
print(car == ‘Audi‘)
print("Is car ==‘audi‘",(car.lower()==‘audi‘))
numbers = 24
print("numbers >= 20:")
print(numbers >= 20)
print("numbers <= 20:")
print(numbers <= 20)
print("numbers >= 20:")
print(numbers >= 20)
print("numbers < 20:")
print(numbers < 20)
print(numbers <= 25 and numbers >= 24)
print(numbers >= 25 or numbers <= 23)
number_values= [10,23,54,54]
print(10 in number_values)
print(11 not in number_values)
alien_colors = [‘green‘,‘yellow‘,‘red‘]
alien_color =alien_colors[0]
if alien_color == ‘green‘:
print("you just earned 5 points")
alien_color =alien_colors[1]
if alien_color == ‘green‘:
print("you just earned 5 points")
else:
print("you are not earned 5 points")
alien_colors = [‘green‘,‘yellow‘,‘red‘]
alien_color =alien_colors[0]
if alien_color == ‘green‘:
print("you just earned 5 points")
elif alien_color ==‘yellow‘:
print("you just earned 10 points")
elif alien_color == ‘red‘:
print("you just earned 15 points")
alien_color =alien_colors[1]
if alien_color == ‘green‘:
print("you just earned 5 points")
elif alien_color ==‘yellow‘:
print("you just earned 10 points")
elif alien_color == ‘red‘:
print("you just earned 15 points")
alien_color =alien_colors[2]
if alien_color == ‘green‘:
print("you just earned 5 points")
elif alien_color ==‘yellow‘:
print("you just earned 10 points")
elif alien_color == ‘red‘:
print("you just earned 15 points")
alien_colors = [‘green‘,‘yellow‘,‘red‘]
alien_color =alien_colors[0]
if alien_color == ‘green‘:
print("you just earned 5 points")
elif alien_color ==‘yellow‘:
print("you just earned 10 points")
elif alien_color == ‘red‘:
print("you just earned 15 points")
alien_color =alien_colors[1]
if alien_color == ‘green‘:
print("you just earned 5 points")
elif alien_color ==‘yellow‘:
print("you just earned 10 points")
elif alien_color == ‘red‘:
print("you just earned 15 points")
alien_color =alien_colors[2]
if alien_color == ‘green‘:
print("you just earned 5 points")
elif alien_color ==‘yellow‘:
print("you just earned 10 points")
elif alien_color == ‘red‘:
print("you just earned 15 points")
age = 24
if age < 2:
print("the person is a baby.")
if age < 4:
print("the person is a toddler.")
if age < 13:
print("the person is a kid.")
if age < 20:
print("the person is a teenager.")
if age < 65:
print("the person is an adult.")
if age >= 65:
print("the person is an elder.")
fruits = [‘cucumber‘,‘apple‘,‘strawberry‘,‘banana‘]
if ‘apple‘ in fruits:
print("You really like apple.")
if ‘banana‘ in fruits:
print("You really like banana.")
if ‘strawberry‘ in fruits:
print("You really like strawberry.")
if ‘cucumber‘ in fruits:
print("You really like cucumber.")
if ‘pear‘ in fruits:
print("You really like pear.")
usernames = ["joey","chandler","monica","ross","rachel","phoebe","admin"]
for name in usernames:
if name == ‘admin‘:
print(f"Hello,{name}, would you like to see a status report.")
else:
print(f"Hello {name},thank you fo logging in again.")
如果为空,就打印消息“We need to find some users!”。
删除列表中的所有用户名,确定将打印正确的消息。
usernames = []
if not usernames:
print("We need to find some users!")
创建一个至少包含5个用户名的列表,并将其命名为current_users 。 再创建一个包含5个用户名的列表,将其命名为new_users ,并确保其中有一两个用户名也包含在列表current_users 中。
遍历列表new_users ,对于其中的每个用户名,都检查它是否已被使用。如果是这样,就打印一条消息,指出需要输入别的用户名;否则,打印一条消息,指 出这个用户名未被使用。
确保比较时不区分大消息;换句话说,如果用户名‘John‘ 已被使用,应拒绝用户名‘JOHN‘
current_users = ["joey","chandler","monica","ross","rachel","phoebe","admin"]
new_users =["Joey","admin","susan","tom"]
for user in new_users:
if user.lower() in current_users:
print(f"you need a new username.{user}")
else:
print(f"the username is available.{user}")
在一个列表中存储数字1~9。 遍历这个列表。
在循环中使用一个if-elif-else 结构,以打印每个数字对应的序数。输出内容应为1st 、2nd 、3rd 、4th 、5th 、6th 、7th 、8th 和9th ,但每个序 数都独占一行。
numbers =[1,2,3,4,5,6,7,8,9,10]
for nubmer in numbers:
if nubmer == 1:
print("1st")
elif nubmer == 2:
print("2nd")
elif nubmer == 3:
print("3rd")
else:
print(f"{nubmer}th")
标签:alt 用户登录 一个用户 class crash 练习 代码 婴儿 获得
原文地址:https://www.cnblogs.com/CodingXu-jie/p/12731296.html