Home > OS >  Why aren't I able to perform simple arithmetic operations in python using Vscode but I can else
Why aren't I able to perform simple arithmetic operations in python using Vscode but I can else

Time:07-15

essentially when I run something as simple as '3 * 3' in any other IDE I have no issues, however, all arithmetic operations in my Vscode seem to return nothing, the terminal just repeats my PWD essentially.

Note that I am new and learning python but everything else thus far has worked fine, print statements print to the terminal etc but maths docent seem to work.

enter code here: def example(val1, val2):
                     return val1 * val2
                 example(2, 6)

Edit: by terminal I mean I am writing the script and clicking the run button in vscode which outputs to said terminal, I have uploaded a SC of what I mean :screenshot of the IDE and terminal output

CodePudding user response:

You don't get any output because you don't do it. You need to add a print() command to get some output:

def example(val1, val2):
  return val1 * val2
result = example(2, 6)
print(result)

CodePudding user response:

Your terminal is running a shell, probably bash not python.

Then, if you want to evaluate that in bash do

$(( 3 * 3 ))
  • Related