ch7 用户输入和while
- input 类似于 scanf
message= input("please input your name:")
print("Hello,"+ message+"!")
- 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])
- 用while循环处理列表和字典
.pop()
.appennd()
.remove()
ch8 函数
- 函数定义
- 传递实参
位置实参
关键字实参
默认值
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')