第七章练习题

7-1

type = raw_input("Which car would you like?")
print("Let me see if I can find you a " + type + ".")
 
 
Which car would you like?bwm
Let me see if I can find you a bwm.
------------------
(program exited with code: 0)

7-2

number = raw_input("How many seats do you need?")
if int(number) > 8:
	print("There is no empty table.")
else:
	print("There is an empty table")
 
 
How many seats do you need?6
There is an empty table
------------------
(program exited with code: 0)
How many seats do you need?9
There is no empty table.
------------------
(program exited with code: 0)

7-5

active = True
while active:
	age = raw_input("How old are you?")
	if age == 'quit':
	   active = False
	else:
	   if int(age) < 3:
		    print("Free.")
	   elif int(age) <= 12:
		    print("$10.")
	   elif int(age) > 2:
	    	print("$15.")
How old are you?4
$10.
How old are you?2
Free.
How old are you?19
$15.
How old are you?quit

------------------
(program exited with code: 0)

7-8

sandwich_orders = ['beef','sheep','fruit','yogurt']
sandwich = ""
while sandwich_orders:
	sandwich = sandwich_orders.pop()
	print("I made you " + sandwich + " sandwich.")
I made you yogurt sandwich.
I made you fruit sandwich.
I made you sheep sandwich.
I made you beef sandwich.


------------------
(program exited with code: 0)





猜你喜欢

转载自blog.csdn.net/gkxin1/article/details/79732539