I'm studying Python, but when I execute the following code, I don't get any errors and it just ends.
Where should I fix or add?
Supplementary information (FW/tool version, etc.)
import math def ex3_4 (vp, vs, t): vp = 6 vs = 3 t = 2 p = (vp * vs)/(vp-vs) * t return (p)
I'm using python3.9
Answer # 1
A python function returns a value when called.
Asuka_wataki's program only defines a function, it doesn't call it.
The python function arguments, in this case vp, vs and t, give the value when called.
When executing a program contained in a file, it will not be output unless a print statement is used.
This program does not require import math.
If you modify these, it will be as follows.
def ex3_4 (vp, vs, t): p = (vp * vs)/(vp-vs) * t return (p) print (ex3_4 (6, 3, 2))
When executed in interactive mode, it will be as follows.
$python Python 3.8.3 (default, Jul 2 2020, 17:30:36) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32 Type "help", "copyright", "credits" or "license" for more information. >>>def ex3_4 (vp, vs, t): ... p = (vp * vs)/(vp-vs) * t ... return (p) ... >>>print (ex3_4 (6, 3, 2)) 12.0
When executed in command execution mode, it will be as follows.
$python ex3_4.py 12.0
Answer # 2
It has been calculated.
def ex3_4 (vp, vs, t) is
We just define a function called ex3_4 with vp, vs, t as variables, so we need to call that function.
Please check the following additions.
import math def ex3_4 (vp, vs, t): # vp = 6 # vs = 3 # t = 2 p = (vp * vs)/(vp-vs) * t return (p) ans = ex3_4 (6,3,2) #function call print (ans) #Display result
By the way, vp, vs, t can be operated from the outside, so I commented them out.
If you give a number in ex3_4 (,,), it will return the number.
- python 3x - i have a question about pipenv i want to set the directory location
- python - [question] about combining pandas data frames
- python 3x - i have a question about sleep in python
- i have a question about runtime errors and exception handling in python
- i have a question about git and github
- python - about hamiltonian neural networks
- python - about write loop to csv
- about python argument and data definition
- python 3x - about downloading anaconda
- python - about the optimum angle of rotation matrix
- python - about downloading youtube videos by youtube-dl
- python - about "" "of" "" select === = "" "
- about processing to exclude the character string group specified from list in python
- python - regular expression wildcard? i have a question about
- python - what i don't understand about yolo9000 (v2)
- about batch change of file name using python
- about the python speedtest code
- about the implementation of combinations in python
- please tell me about the role of python tag = "mychr"
- python - you may need to restart the kernel to use updated packages error
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to check the type of a shell script variable
- i want to call a child component method from a parent in vuejs