PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, December 11, 2022

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

 December 11, 2022     python, syntax, syntax-error     No comments   

Issue

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}.') ^


Solution

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
Answer Checked By - Katrina (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing