I am trying to run my sample code containing functions but get the following error when running from the command line.
python: can't open file 'Functions.py': [Errno 2
I have checked my environment variables and also reviewed my code. I am currently using JetBrains Pycharm 2018.3.2 version, could this be the issue?
Based on your comments, your code should be like this:
def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)
if __name__ == '__main__':
My1st()
Notice the concatenation in the print
statement and the name attribute. and then if you're on windows(as it looks like you are),
py Functions.py
should give you the output: 3
Errno 2
points out at a file or directory not being found (in this case 'Functions.py'). Could you check whether your path to Functions.py is correct?
there was an error in below line of your code
print("The result is " + result)
the problem is that you can't concatenate string with int value
and also i am not able to understand you problem but below are some code that you may want from your problem statement.
def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)
if __name__ == "__main__" :
My1st()
OR
def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)
My1st()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.