python ch7 while

# 用户输入和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)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值