def PrintName():
print("P P "," M M ","X X")
print("P P "," M M M M "," X X ")
print("P P ","M M M "," X X ")
print("P P "," M M "," X ")
print("P "," M M M M "," X X ")
print("P "," M M M M "," X X ")
print("P ","M M M ","X X")
PrintName()
11-2
def printanything(arr = []):
size = len(arr)
for i in range(size):
print(arr[i],end=" ")
tom = ["TOM","is","a","boy","."]
printanything(tom)
11-3
def calculateTax(price,tax_rate):
total = price + price * tax_rate
global my_price
print ("my_price (inside function)= %.2f"%my_price)
return total
my_price = float(input("enter a price:"))
totalprice = calculateTax(my_price,0.06)
print("my_price = %.2f"%my_price,"total price = %.2f"%totalprice)
print("my_price (outside function) = %.2f"%my_price)
11-4
def total_money(five_coin,two_coin,one_coin):
total = 5 *five_coin + 2 * two_coin +1 * one_coin
return total
five = int(input("请输入5分个数:"))
two = int(input("请输入2分个数:"))
one = int(input("请输入1分个数:"))
total = total_money(five,two,one)
print("total is %.2f"%total)