python note3

ch7 用户输入和while

  1. input 类似于 scanf
message= input("please input your name:")
print("Hello,"+ message+"!")

在这里插入图片描述

  1. while

动手试一试
7-4:

prompt = "please enter the toppings of pizaa:\n"
prompt += "please enter quit to end the program"

message=''
while message != "quit":
    message = input(prompt)
    if message != "quit":
        print("we will add"+message+" to the pizza")

7-5:

prompt = "please enter your age:\n"

message = '' # message 初始化
price=('free','3元','6元')
while message != 'quit':
    message = input(prompt)
    message = int(message)  # 类型转换
    if message <= 3:
        print("your ticket price is "+ price[0])
    elif message<=12:
        print("your ticket price is " + price[1])
    else:
        print("your ticket price is " + price[2])
  1. 用while循环处理列表和字典
    .pop()
    .appennd()
    .remove()

ch8 函数

  1. 函数定义
  2. 传递实参
    位置实参
    关键字实参
    默认值

8-3

def make_shirt(size,font_style):
    print("the size of T-shirt is "+size+" and the font style is "+font_style)

make_shirt("6","songti")  #位置实参

make_shirt(size="8",font_style="hua") #关键字实参

8-4

def deccribe_city(city_name,country='China'):
    print(city_name +" is in "+country)

deccribe_city('shanghai')
deccribe_city('beijing')
deccribe_city('toyko','janpan')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

闪闪发亮的小星星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值