Python script running differently in terminal?

I am on Zorin OS 16 Lite, as up to date as i can get it.

Ok, so i have written a Python script which heavily utilises the end="\r" command to write out terminal prompts one letter at a time. I want to run it in my terminal instead of VSCode, but when I try to, it gives me the error:

$ python main.py
** File "main.py", line 32**
** print(sentence, end="\r")**
** ^**
SyntaxError: invalid syntax

Thing is, it runs perfectly in VSCode. However, if I use the command: $ python3 main.py It will run, but it outputs everything twice. Here is the code, because it could be helpful i guess. The 'say' function is what is giving me trouble. if anyone knows whats going on i would be really greatful. thanks!

#loads of terminal UI cause i dunno what to make and it could be useful

#libraries

import time
import os

#QOL and basic functions

def wait(seconds): #its just shorter
** time.sleep(seconds)**

def blank(): #do the blank line bro
** print(' ')**

def cls(): #EZ 2 remember
** os.system('clear')**

def split(word): #splits individual letters in a word (thanks Kyle lol)
** return [char for char in word]**

def say(thing, delLast): #prints a sentence one letter at a time, it probably could be better but i cba
** thingSplit = split(thing)

** thingLength = len(thingSplit)**
** lettersPrinted = 0**
** sentence = ""**
** while lettersPrinted != thingLength:**
** sentence = sentence + thingSplit[lettersPrinted]**
** print(sentence, end="\r")**
** wait(0.015)**
** lettersPrinted = lettersPrinted + 1**
** if delLast == 'end="\r"':**
** print(sentence, end='\r')**
** else:**
** print(sentence)**

**#functions **

#draw HP bars, using ALL the variables
def drawBars(playerName, playerLevel, maxPlayerHP, playerHP, enemyName, enemyLevel, maxEnemyHP, enemyHP):

** playerHPDecimal = playerHP / maxPlayerHP #makes hp into a decimal (so 10/100 becomes 0.01, 50/200 becomes 0.25 etc.)**
** enemyHPDecimal = enemyHP / maxEnemyHP #does the same as B4**

** #do the player hp bars**

** print( playerName,', Level ', playerLevel)**


** print('|====================|')**

** #find correct health bar to display for player**
** if playerHPDecimal >= 0.9 and playerHPDecimal <= 1:**
** print('|####################|')**
** elif playerHPDecimal >= 0.8 and playerHPDecimal <= 0.9:**
** print('|################ |')**
** elif playerHPDecimal >= 0.7 and playerHPDecimal <= 0.8:**
** print('|############## |')**
** elif playerHPDecimal >= 0.6 and playerHPDecimal <= 0.7:**
** print('|############ |')**
** elif playerHPDecimal >= 0.5 and playerHPDecimal <= 0.6:**
** print('|########## |')**
** elif playerHPDecimal >= 0.4 and playerHPDecimal <= 0.5:**
** print('|######## |')**
** elif playerHPDecimal >= 0.3 and playerHPDecimal <= 0.4:**
** print('|###### |')**
** elif playerHPDecimal >= 0.2 and playerHPDecimal <= 0.3:**
** print('|#### |')**
** elif playerHPDecimal >= 0.1 and playerHPDecimal <= 0.2:**
** print('|## |')**
** elif playerHPDecimal >= 0 and playerHPDecimal <= 0.1:**
** print('|~ |')**

** print('|====================|')**

** print(playerHP, '/', maxPlayerHP)**

** #space it out man**


** blank()**

** #now the enemy**

** print(enemyName,', Level', enemyLevel)**

** print('|====================|')**

** #find correct bar to display for enemy**
** if enemyHPDecimal >= 0.9 and enemyHPDecimal <= 1:**
** print('|####################|')**
** elif enemyHPDecimal >= 0.8 and enemyHPDecimal <= 0.9:**
** print('|################ |')**
** elif enemyHPDecimal >= 0.7 and enemyHPDecimal <= 0.8:**
** print('|############## |')**
** elif enemyHPDecimal >= 0.6 and enemyHPDecimal <= 0.7:**
** print('|############ |')**
** elif enemyHPDecimal >= 0.5 and enemyHPDecimal <= 0.6:**
** print('|########## |')**
** elif enemyHPDecimal >= 0.4 and enemyHPDecimal <= 0.5:**
** print('|######## |')**
** elif enemyHPDecimal >= 0.3 and enemyHPDecimal <= 0.4:**
** print('|###### |')**
** elif enemyHPDecimal >= 0.2 and enemyHPDecimal <= 0.3:**
** print('|#### |')**
** elif enemyHPDecimal >= 0.1 and enemyHPDecimal <= 0.2:**
** print('|## |')**
** elif enemyHPDecimal >= 0 and enemyHPDecimal <= 0.1:**
** print('|~ |')**

** print('|====================|')**

** print(maxEnemyHP,'/',enemyHP)**

#preload / setup

running = True
cls()

#code

#select element to play
while running == True:

** say('UI showcase V 1.O')**
** say('element list:')**
** say('1. Health bars')**
** say('2. idk')**

** userIn = input('>')**

** cls() #clear screen for looks**

** if userIn == '1':**

** playerName = input('enter player name: ')**
** playerLevel = int(input('enter player level: '))**
** maxPlayerHP = int(input('enter max player HP: '))**
** playerHP = int(input('enter player HP: '))**

** enemyName = input('enter enemy name: ')**
** enemyLevel = int(input('enter enemy level: '))**
** maxEnemyHP = int(input('enter max enemy HP: '))**
** enemyHP = int(input('enter enemy HP: '))**

** cls()**

** #these variables should be self-explanitory**
** drawBars(playerName, playerLevel, maxPlayerHP, playerHP, enemyName, enemyLevel, maxEnemyHP, enemyHP)**

** wait(20)**

** cls()**

** elif userIn == '2':**

** say('he does not know bro')**

** wait(1)**

** cls()**

** elif userIn == 'kill':**

** exit()**

It looks like you have more than one python version installed (which is normal) and you are seeing variance on which is used. Try adding from __future__ import print_function to ensure you are using python 3+.
Also, you can:
print(sentence,end='\r')

1 Like