与小卡特一起学python 第13章 函数-积木 动手试一试

本文介绍了三个Python函数编程实例,包括打印个性化名字图案、详细地址信息及计算含税价格等,通过这些实例帮助读者掌握函数定义与调用的基本方法。
# 13函数 动手试一试
#13.1 编写一个函数,用大写字母打印你的名字。
def printName():
    print("   CCCC       A      RRRRR   TTTTTTT  EEEEEE  RRRRR")
    print(" C      C   A   A    R    R     T     E       R    R")
    print("C          A     A   R    R     T     EEEEEE  R    R")
    print(" C        AAAAAAAAA  RRRRRR     T     E       RRRRRR")
    print("  C     CA         A R    R     T     E       R    R")
    print("   CCCC A           AR     R    T     EEEEEE  R      R")
    print()

for i in range(5):
    printName()  #若是加print(printName()) 则会出现none值

#13.2 建立一个函数,可以打印全世界人名、地址、街道、城市、州、省,邮编和国家
def printAdress(name,address,street,city,code,country):
    print(name)
    print(address)
    print(street)
    print(city)
    print(code)
    print(country)
printAdress("jack","303#","NO1","North","01001","RUSSIA")

#13.3 13-7列子,要求my_price是全局变量
def calculateTax(price,tax_rate):
    total = price +(price * tax_rate)
    global my_price
    my_price = 1000
    print("my_price (inside function) = ",my_price)
    return total
my_price = float (input("Enter a price:"))
totalPrice = calculateTax(my_price,0.06)
print("price = ",my_price,"Total price = ", totalPrice)
print("my_price (outside function) =",my_price)

#13.4 计算零钱的总值
def countNo(quarters,dimes,nickels,pennies):
    total = quarters * 5 +dimes * 2 + nickels *1 +pennies
    return total  #返回值
quarters = int(input())
dimes = int(input())
nickels= int(input())
pennies = int(input())

total = countNo(quarters,dimes,nickels,pennies)
print(total)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/220205/viewspace-2075849/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/220205/viewspace-2075849/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值