Below is the code:
def add(a,b):
return a + b
while True:
try:
a=float(input('Please enter a number'))
break
except:
print ('Invalid Number, please re-enter')
while True:
try:
b=float(input('Please enter a number'))
break
except:
print ('Invalid Number, please re-enter')
print(add(a,b))
Scenario: I created a Python file via PowerShell and edited it in VS Code. And, I got a similar error.
Problem: Apparently Powershell and VS Code use conflicting encoding schemas. For details see:
Understanding file encoding in VS Code and PowerShell
My Solution: Recreate file in VS Code.
I think the issue may be how you are calling it form the command line. You should change directories to where your python interpreter is and then point it to the script
c:\users\test>cd c:\python2.7
c:\python2.7>python.exe "c:\users\test\desktop\test_script.py"
Just use the path to your python exe and then replace my desktop with the path to your script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With