Why does my python code run perfectly fine on runestone but not on vscode?

Question:

def CreditPay(rate, payment, verbose):
    balance = 1000 # Amount currently owed
    month = 1  #Number of months
    paid = 0    # Amount paid so far

    while balance > payment:
        balance = balance + balance*rate/100 - payment
        paid += payment
        if verbose:
            print(f'Balance after month {month} is $ {balance}.')

        month += 1
    print(f"Final payment is $ {balance}")
    print(f'Final amount paid is $ {balance+paid}')
        
    return month

nmonths = CreditPay(2.5,100,False)
print("Number of months to pay off is", nmonths)

nmonths = CreditPay(2.5,100,True)
print("Number of months to pay off is", nmonths)

                                                   ^

SyntaxError: invalid syntax
martin@Martins-Air ~ % python -u "/Users/martin/Downloads/assignment7"
File "/Users/martin/Downloads/assignment7", line 19
print(f’Balance after month {month} is $ {balance}.’)
^

Asked By: Martin

||

Answers:

What python interpreter are you using? f-string got introduced in python3.
To select your python interpreter with Vscode open up the command line windows ctrl+shift+p or macos cmd+shift+p and then search for "python interpreter".
the complete command should look like this

>Python: Select Interpreter and then simply click on any Python 3.x.x

Hope this helps!

Answered By: Nara Tekchuen

My problem was I downloaded code runner extension. I had to go to its settings.json and change python -u to python3 -u. thanks for the help. still new to programming.

Answered By: Martin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.