1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| def greet_user(): print("Hello!")
greet_user()
def greet_user(username): print("Hello, "+username.title()+"!")
greet_user("jesse")
def describe_pet(animal_type,pet_name): print("\nI have a "+animal_type+".") print("My "+animal_type+"'name is "+pet_name.title()+".")
describe_pet('hamster','harry')
describe_pet(animal_type='hamster',pet_name='harry')
def show(name='Sang',city='Guoyang'): print(name+" is living in "+city)
show()
def get_formatted_name(first_name,last_name): full_name=first_name+' '+last_name return full_name.title()
musician=get_formatted_name('jimi','hendrix') print(musician)
def get_formatted_name(first_name,last_name,middle_name=''): if middle_name: full_name=first_name+' '+middle_name+' '+last_name else: full_name=first_name+' '+last_name return full_name.title()
musician=get_formatted_name('jimi','hendrix') print(musician)
musician=get_formatted_name('john','hooker','lee') print(musician)
def build_person(first_name,last_name): person={'first':first_name,'last':last_name} return person
musician=build_person('jimi','hendrix') print(musician)
def build_person(first_name,last_name,age=''): person={'first':first_name,'last':last_name} if age: person['age']=age return person
musician=build_person('jimi','hendrix',age=27) print(musician)
def greet_users(names): for name in names: msg="Hello, "+name.title()+"!" print(msg)
usernames=['hannah','ty','margot'] greet_users(usernames)
def clear(names): while names: names.pop()
clear(usernames[:]) print(usernames)
def make_pizza(*toppings): print(toppings)
make_pizza('pepperoni') make_pizza('mushrooms','green peppers','extra cheese')
def make_pizza(size,*toppings): print("\nMaking a "+str(size)+"-inch pizza with the following toppings:") for topping in toppings: print("- "+topping)
make_pizza(16,'pepperoni') make_pizza(12,'mushroom','green peppers','extra cheese')
def build_profile(first,last,**user_info): profile={} profile['first_name']=first profile['last_name']=last for key,value in user_info.items(): profile[key]=value return profile
user_profile=build_profile('albert','einstein',location='princeton',field='physics') print(user_profile)
|