Advanced programming technology four weeks work

Source: Internet
Author: User

Seventh Chapter

7-1

Car = input ("What kind of cars does you want?")
Print ("Let me see if I can find you a" + Car + ".")

7-2

Number = input ("How many is coming here?")
Number = Int (number)
if number > 8:
	print ("Sorry, there is no tables available.")
else:
	print ("OK, we have a table for you.")


7-3

Number = input ("Please enter a number.")
Number = Int (number)
remainder = number%
If remainder:
	print (str (number) + "isn ' t an exact multiple of ")
Else:
	print (str (number) +" is an exact multiple of 10. ")


7-4

Message = "What ingredients want to add?"
INGREDIENTS = "while
ingredients! = ' Quit ':
	ingredients = input (message)
	if ingredients = = ' quit ':
		BR Eak
	Print (ingredients)

7-6

Message = "How old is you?"
Active = True while
active: Age
	= input (message)
	if age = = ' quit ':
		active =
		False
	= Int (age)
	if age < 3:
		print ("You can watch it for free.")
	Elif Age <=: Print ("You'll need to pay for $ $ for
		the cinema tickets.")
	else: Print ("You'll need to pay for $ $ for
		the cinema tickets.")


7-8

Sandwich_orders = ["Tofu sandwich", "Tuna sandwich", "turkey Sandwich"]
finished_sandwiches = [] While
Sandwich_ Orders:
	sandwich = sandwich_orders.pop (0)
	print ("I made your tuna sandwich," + Sandwich + ".")
	Finished_sandwiches.append (Sandwich)
print ("\ n") for
sandwich in finished_sandwiches:
	print ( Sandwich


7-9

Sandwich_orders = ["Tofu sandwich", "pastrami", "pastrami", "Tuna sandwich", "turkey Sandwich", "pastrami"]
finished _sandwiches = []
print ("The delicatessen sold out all the pastrami.")
While "Pastrami" in Sandwich_orders:
	sandwich_orders.remove ("pastrami") while
sandwich_orders:
	Sandwich = Sandwich_orders.pop (0)
	finished_sandwiches.append (sandwich)
print ("\ n") for
Sandwich In finished_sandwiches:
	print (sandwich)

Eighth Chapter

8-1

Def display_message ():
	print ("I learned how to use functions in this chapter.")
Display_message ()

8-2

def favorite_book (title):
	print ("One of my favorite books is" + title + '. ')
Favorite_book ("Alice in Wonderland")

8-3

def make_shirt (size, logo):
	print ("This was a" + Size + "T-shirt with" + "' + Logo + '".)
Make_shirt ("Large", "I Love Python")
make_shirt (size = "large", logo = "I love Python")

8-4

def make_shirt (size = "large", logo = "I love Python"):
	print ("It's a" + Size + "T-shirt with" + "+" + Logo + '".')
Make_shirt (size = "large")
make_shirt (size = "middle")
make_shirt (size = "small", logo = "I love China")

8-6

Def city_country (city, Country):
	message = ' "' + City + ', ' + Country + '" '
	print (message)
city_country (" Santiago "," Chile ")
city_country (" Beijing "," China ")
city_country (" London "," Britain ")

8-7

Def Make_album (singer, album, Tracks_number = 0):
	albums = {}
	albums["singer ' s name"] = singer
	albums["album ' s name "] = album
	if tracks_number:
		albums[" tracks_number "] = Tracks_number
	return albums
print ( Make_album ("PJ Harvey", "Stories from the city,stories from the Sea"))
print (Make_album ("Chuck Berry", "the Great Twenty-eight "))
print (Make_album (" M.I.A. "," Kala "))
print (Make_album (" Brian Wilson "," SMiLE ", 17))

8-8

Def make_album ():
	active = True while
	active:
		albums = {}
		singers_name = input ("Please enter the Singe R ' s name:\n (enter ' Q ' at any time to quit) \ n ")
		if singers_name = = ' Q ':
			active = False break
			;
		Albums_name = input ("Please enter the album ' s name:\n (enter ' Q ' for any time to quit) \ n")
		if albums_name = = ' Q ':
			Active = False break
			;
		Tracks_number = input ("Please enter the tracks ' name:\n (enter ' Q ' for any time to quit) \ n")
		if tracks_number = = ' Q ':
			active = False break
			;
		albums["singer s name"] = Singers_name
		albums["album ' name"] = Albums_name
		albums["Tracks ' number"] = tracks _number
		print (albums)
Make_album ()

8-9

def show_magicians (list): For
	name in list:
		print (name)
orders = ["Tom", "Jack", "Jimy"]
Show_magi Cians (Orders)

8-10

def show_magicians (lists): for
	name in lists:
		print (name)
def make_great (lists):
	length = len (lists )
	for index in range (0, length):
		Lists[index] = "The great" + Lists[index]
orders = ["Tom", "Jack", "Jimy"]
make_great (Orders)
Show_magicians (orders)

8-11

def show_magicians (lists): for
	name in lists:
		print (name)
def make_great (lists):
	length = Len (li STS) for
	Index in range (0, length):
		Lists[index] = "The great" + Lists[index]
	show_magicians (lists) 
  orders = ["Tom", "Jack", "Jimy"]
make_great (orders[:])
Show_magicians (orders)

8-12

def sandwich_toppings (*toppings):
	print ("This sandwich was made of the following toppings:") for
	topping in top Pings:
		print ("-" + topping)
sandwich_toppings (' onions ')
sandwich_toppings (' green peppers ', ' bread ')
sandwich_toppings (' sausage ', ' Green vegetables ', ' chicken ')

8-13

Def build_profile (First, Last, **user_info): Profile
	= {} profiles
	[' first_name '] = First profile
	[' Last_nam E '] = Last
	for key, value in User_info.items (): Profile
		[key] = value
	return profile
user_profile = Buil D_profile (' Wang ', ' Chen ', sex = ' male ', age = ' $ ', weight = ' max ')
print (user_profile)

8-15

printing_functions.py

def print_models (Unprinted_designs, completed_models): While
	unprinted_designs:
		current_design = unprinted _designs.pop ()
		print ("Printing model:" + current_design)
		completed_models.append (current_design)
def show_completed_models (completed_models):
	print ("\nthe following models has been printed:")
	for Completed_model in Completed_models:
		print (Completed_model)

printing_functions.py

From printing_functions import *
unprinted_designs = [' iphone case ', ' Robot pendant ', ' dodecahedron ']
completed _models = []
print_models (unprinted_designs, Completed_models)
show_completed_models (completed_models)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.