Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the python function

Shulou Source: shulou.com Published: 2022-06-02 01:49:19 10月04日 Update

This article introduces the relevant knowledge of "how to use the python function". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

# 13 function

# 13.1 write a function to print your name in capital letters.

Def printName ():

Print ("CCCC A RRRRR TTTTTTT EEEEEE RRRRR")

Print ("C C An A R R T E R R")

Print ("C An 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 An AR R T EEEEEE R R")

Print ()

For i in range (5):

PrintName () # if you add print (printName ()), the none value will appear.

# 13.2 create a function that can print names, addresses, streets, cities, states, provinces, zip codes and countries all over the world

Def printAdress (name,address,street,city,code,country):

Print (name)

Print (address)

Print (street)

Print (city)

Print (code)

Print (country)

PrintAdress ("jack", "309", "NO1", "North", "01001", "RUSSIA")

# 13.3 13-7 columns, which requires my_price to be a global variable

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 calculate the total value of change

Def countNo (quarters,dimes,nickels,pennies):

Total = quarters * 5 + dimes * 2 + nickels * 1 + pennies

Return total # return value

Quarters = int (input ())

Dimes = int (input ())

Nickels= int (input ())

Pennies = int (input ())

Total = countNo (quarters,dimes,nickels,pennies)

Print (total)

This is the end of the content of "how to use the python function". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Function content more knowledge practical successful next person name world global variable name dilemma country address city uppercase capital letter actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker Linux Xiaomi Shulou Tech Info