# 获取列表前三个值,并打印出其值
players =['charles','martina','michael','florence','eli']print("Here are the first three players on my team:")for player in players[:3]:print(player.title())
current_users_lower =[]
current_users =('Rim','cate','tom','lucy','Admin')for user in current_users:
current_users_lower.append(user.lower())#
new_users =('cate','Tom','Adminn')iflen(current_users_lower)==0:print("We need to find some users!")else:for user in new_users:if user.lower()in current_users_lower:print(f"the {user} username have in our web system yet, please try other one?")else:print(f"congratilation u can use the {user} username to login our website")
prompt ="Tell me how old are you ,I will tell the price of tickets,pls !!!"
prompt +="\nOr you will now be not allow to go to cinime!!!\n"whileTrue:
age =input(prompt)if age =="quit":breakelse:
age =int(age)if age <3:print(f"你现在是{age}岁,你可以免费获得电影票!!!")elif age <12:print(f"你现在是{age}岁,你需要10美元获得电影票!!!")else:print(f"你现在是{age}岁,你需要15美元获得电影票!!!")
• 使用变量active来控制循环结束的时机。
prompt ="Tell me how old are you ,I will tell the price of tickets,pls !!!"
prompt +="\nOr you will now be not allow to go to cinime: \n"
flag =Truewhile flag:
age =input(prompt)if age =="quit":
flag =Falseelse:
age =int(age)if age <3:print(f"你现在是{age}岁,你可以免费获得电影票!!!")elif age <12:print(f"你现在是{age}岁,你需要10美元获得电影票!!!")else:print(f"你现在是{age}岁,你需要15美元获得电影票!!!")
• 在while循环中使用条件测试来结束循环。
prompt ="Tell me how old are you ,I will tell the price of tickets,pls !!!"
prompt +="\nOr you will now be not allow to go to cinime: \n"
age =" "while age !="quit":
age =input(prompt)if age !="quit":
age =int(age)if age <3:print(f"你现在是{age}岁,你可以免费获得电影票!!!")elif age <12:print(f"你现在是{age}岁,你需要10美元获得电影票!!!")else:print(f"你现在是{age}岁,你需要15美元获得电影票!!!")