【Week4.1】第七章(用户输入和While循环)

第七章:
1.在python2系列中使用input()函数输入字符串的时候需要加上引号才能正常运行;原来python2.7中正确的应该是raw_input()这个函数;
2.使用raw_input()这个函数,所以此时数字也是int类型的,所以进行比较的时候需要改变字符串为int型,但是不知道为什么没有报错,而是直接打印了;
3.7-2后面的练习不知道为什么有点奇怪标记为$$$$,一直无法正常退出程序,原来是少了break;
4.7-5这里针对python2.7版本中关于input()和raw_input()两种的区别还是不一样的呀~,当换成input()的时候,数字就是有效的了!
5.7-6里面发现条件测试时真的每个条件都去测试一下,一个个测试下来,所以条件测试的顺序也很重要;
6.7-8里面对空列表的定义不太熟悉,导致报错;

#7-1
message = raw_input('What kind of cars do you want? ')
print('OK, Let me see if i can find a Subaru.')

#7-2
number = raw_input('How many people will come to lunch? ')
if int(number) >= 8:
	print('Sorry, there is no empty table.')
else:
	print('OK, no problems.') 



#7-3
number = raw_input("Please input a number: ")
number = int(number)
if number % 10 == 0:
	print("Yes!")
else:
	print('No!')




#7-4
prompt = "Please input what you want in pizza: "
message = ''
while message != 'quit':
	message = raw_input(prompt)
	if message != 'quit':
		print ('OK, we will add it to your pizza')

#7-5
prompt = 'Please input your age to buy the ticket: '
age = ''
money = ''
while True:
	age = input(prompt)
	if age < 3:
		money = 0
	elif 3 <= age <= 12:
		money = 10
	elif age > 12:
		money = 15
	print(money)
	


#7-6
prompt = 'Please input your age to buy the ticket: '
active = True
age = ''
money = ''
while active:
	age = raw_input(prompt)
	if age == 'quit':
		#active = False
		break
	elif int(age) < 3:
		money = 0
	elif 3 <= int(age) <= 12:
		money = 10
	elif int(age) > 12:
		money = 15
	print(money)


#7-7
x = 1
while x <= 5:
	print(x)



#7-8
sandwich_orders = ['fruits', 'vegatables', 'meat']
finished_sandwiches = []
while sandwich_orders:
	print("I made your tuna sandwich.")
	sandwich = sandwich_orders.pop()
	finished_sandwiches.append(sandwich)
for finished_sandwiche in finished_sandwiches:
	print(finished_sandwiche)


#7-9
sandwich_orders = ['fruits', 'pastrami', 'vegatables', 'pastrami', 'meat', 'pastrami']
print(sandwich_orders)
while 'pastrami' in sandwich_orders:
	sandwich_orders.remove('pastrami')
print(sandwich_orders)
print("Sorry, pastrami has been sold out")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值