# 用户输入和while循环
# 如何在程序中使用input()来让用户提供信息;如何处理文本和数字
# 输入,以及如何使用while循环让程序按用户的要求不断地运行;多种控制while循环流程的方式:
# 设置活动标志、使用break语句以及使用continue语句;如何使用while循环在列表之间移动元素,
# 以及如何从列表中删除所有包含特定值的元素;如何结合使用while循环和字典
# 1 input() 函数
# message = input("Tell me something, and I will repeat it back to you: ")
# print(message)
#
# name = input("Please enter your name: ")
# print("Hello, " + name + "!")
#
# prompt = "If you tell us who you are, we can personalize the messages you see."
# prompt += "\nWhat is your first name? "
# name = input(prompt)
# print("\nHello, " + name + "!")
# # input() 将输入解读成了字符串
# height = input("How tall are you, in inches? ")
# height = int(height)
# if height >= 36:
# print("\nYou're tall enough to ride!")
# else:
# print("\nYou'll be able to ride when you're a little older.")
# 求模运算 % 两个数相除并返回余数
print(8 % 3)
# 2 while 循环
print(" ")
current_number = 1
while current_number <= 5:
print(current_number)
current_number += 1
# 删除包含特定值的所有列表元素
print(" ")
pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']
print(pets)
while 'cat' in pets:
pets.remove('cat')
print(pets)
python ch7 while
最新推荐文章于 2024-07-18 15:53:23 发布