程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

How to use Python return to implement exchange rate converter

編輯:Python

How do you use it? python return Implement exchange rate converter

This article mainly explains “ How do you use it? python return Implement exchange rate converter ”, The explanation in the text is simple and clear , Easy to learn and understand , Next, please follow Xiaobian's ideas and go deeper slowly , Study and learn together “ How do you use it? python return Implement exchange rate converter ” Well !

A. Course content

Mainly learn the return value of the function returm, Through learning to write an exchange rate converter program .

B. Knowledge point

(1) Defined function

(2) Call function

(3) Return value

C. Basic instructions used

(1)def

(2)return

(3)input

(4)print()

D. Function return value

The return value of a function refers to the value returned after the function is executed . Why should there be a return value ? Because after this function operation is completed , Its results will be used in the following program . Return values allow you to transfer most of the heavy work of the program to functions , To simplify the process .

In the function , have access to return Statement to return the value to the line of code that called the function ,return Is the end of a function , There can be more than one in a function return, But just do it once , The whole function will end . Here's the picture :

Each function has a return value , If the return value is not specified in the function , stay Python After the function execution is completed , By default, a None. Functions can also have multiple return values , If there are multiple return values , Will put all the returned values into a tuple , A tuple is returned .

E. Write exchange rate converter program

This example will be implemented in combination with the return value of the function . We use the formula to calculate the exchange rate in the function , Then let the function return the result of the calculation , As shown in the figure below :

(1) Defined function rate(),x and y For its two formal parameters .x The received argument is the number of currencies ,y The received argument is the exchange rate value .

(2) Put the variable c The value of is returned to the function call line .

(3) Defined function currency(),cur For its formal parameters .cur The received argument is currency type .

(4) use if-else Conditional statements determine which currency the user enters . Just create a new variable r, Assign the exchange rate of the corresponding currency to the variable r.

(5) Put the variable r The value of is returned to the function call line .

(6) New variable currency1, Assign the value entered by the user to the variable currency1.

(7) New variable money, Assign the value of money entered by the user to the variable money.int() Function converts the amount of money entered by the user into an integer .

(8) New variable currency2, Call function currency(), Assign the returned value to the variable currency2. The argument when calling the function is the currency type entered by the user .

(9) New variable rmb, Call function rate(), Assign the returned value to the variable rmb. The arguments when calling the function are the amount of money entered by the user and currency2 Value .

Thank you for reading , That's all “ How do you use it? python return Implement exchange rate converter ” Content. , After learning this article , I believe everyone knows how to use it python return We have a deeper understanding of the problem of realizing the exchange rate converter , The specific use needs to be verified by practice . This is billion speed cloud , Xiaobian will push you articles with more relevant knowledge points , Welcome to your attention !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved