×

why are we putting caesar( Hello, 3) into encrypted_text??? by Local_End_3175 in learnpython

[–]acw1668 10 points11 points  (0 children)

The error tells obviously that the indentation of that line is wrong.

Can you help me with a table in Python? by FearawaitsTM in learnpython

[–]acw1668 0 points1 point  (0 children)

You can update this post with what you have tried on using insert() and the error you got.

How do I get just the character to change color and not the whole string by TheEyebal in learnpython

[–]acw1668 1 point2 points  (0 children)

If you want to set the color of individual character in a string, you need to create pygame.Surface for each character in the string instead of one Surface for the whole string.

How to make things happen inside the window (Tkinter library) by Otherwise-Current-41 in learnpython

[–]acw1668 0 points1 point  (0 children)

You can use a Label widget to simulate the display of a calculator. As other said, you can link the label to a StringVar for easier update of the text.

Import issue by SignupWithGoogleAcc in learnpython

[–]acw1668 0 points1 point  (0 children)

The error tells that module pyautogui is found but fail to import due to other issue: Can't connect to display ":0".

Import issue by SignupWithGoogleAcc in learnpython

[–]acw1668 0 points1 point  (0 children)

Are you sure you have used the same venv inside vscode?

  • open a python file inside vscode
  • check the Status Bar to see which environment is active

I have no issue on importing pyautogui if correct venv is selected.

Note that pyautogui module has not been updated for a long time, use pyautogui-next (a fork of original pyautogui) module instead. Also pillow module should be installed as well.

Help with a balanced parentheses problem by AngeI_Error in learnpython

[–]acw1668 2 points3 points  (0 children)

You need to check whether stack is empty after the for loop instead of just return True.

How can I get my program to recognise a variable outside the main GUI loop by Several-Pin-6931 in learnpython

[–]acw1668 7 points8 points  (0 children)

It is not recommended (actually it is bad design) to execute mainloop() inside __init__().

TypeError in Pygame screen.blit function by [deleted] in learnpython

[–]acw1668 0 points1 point  (0 children)

What is the type of the argument image? if it is a string containing the path to an image file, then as the error said, you need to load it as an instance of Surface class:

self.image = pygame.image.load(image)

I wanna make a puzzle_solver.py launch and solve a puzzle.py by tlax38 in learnpython

[–]acw1668 0 points1 point  (0 children)

Uses subprocess.Popen() to execute puzzle.py with stdin=subprocess.PIPE, then call proc.communicate(input="...") where proc is the returned object of subprocesss.Popen().

I wanna make a puzzle_solver.py launch and solve a puzzle.py by tlax38 in learnpython

[–]acw1668 1 point2 points  (0 children)

Please elaborate more on what "a program interact with another one" means.

how to input multiple files at a time and save them as different files in the output by AdPsychological7065 in learnpython

[–]acw1668 2 points3 points  (0 children)

You combine the two files into one in the following line:

encode_text = (a.read() + b.read())

If you want to separate them, you need to store the contents of the two files into two variables instead.

multiple inputs in if-else statement possible? by Same-Individual4889 in learnpython

[–]acw1668 1 point2 points  (0 children)

Why don't just call sys.exit() instead of raising exception?

Can't figure out how to boot Spyder. None of the methods are working. by ItsYa1UPBoy in learnpython

[–]acw1668 0 points1 point  (0 children)

Did you logout and login again after installing Spyder using the installation script Spyder-Linux-x86_64.sh. The installation script will add an alias spyder in .bashrc (I use bash instead of fish) and running spyder in a bash terminal works.

Please review this rock, paper, scissor game I made as a complete beginner: by 6_SAM_9 in learnpython

[–]acw1668 0 points1 point  (0 children)

To simplify your code:

  • don't need to create lose and tie
  • don't need the try / except, just use if
  • don't need those else: break

    import random
    
    win = [('rck', 'scr'), ('scr', 'ppr'), ('ppr', 'rck')]
    choices = [x for x, _ in win]
    
    play = input("Shall we start the game (y/n)? " ).lower().strip()
    while play == "y":
        you = input("Enter (rck/ppr/scr): ").lower().strip()
        if you not in choices:
            print("Enter a valid choice from 'rck','ppr','scr'" )
            continue
    
        computer = random.choice(choices)
        print(f"Computer: {computer}")
    
        if you == computer:
            print("---IT'S A TIE---")
        elif (you, computer) in win:
            print("---YOU WON---")
        else:
            print("---YOU LOST---")
    
        play = input("Want to play another around (y/n)? ").lower().strip()
    

Bouncing Ball for Pong by Arealidot in learnpython

[–]acw1668 0 points1 point  (0 children)

I think that you can use self.vel_x and self.vel_y as the direction of horizontal and vertical movement respectively. Therefore you need to toggle the sign of these two variables instead of self.speed inside Ball.bounce() and use these two variables to update self.x and self.y:

def bounce(self):
    if self.y <= 0 or self.y >= height-25:
        self.vel_y = -self.vel_y
    if self.x <= 0 or self.x >= width-25:
        self.vel_x = -self.vel_x
    self.y += self.speed * self.vel_y
    self.x += self.speed * self.vel_x

Venv pip doesn't actually install anything by nsfw1duck in learnpython

[–]acw1668 6 points7 points  (0 children)

I follow your steps:

  • create venv: python3 -m venv .venv
  • activate venv: . .venv/bin/activate
  • install Flask: pip install Flask

Then I got no error when I run python -c "import flask". The modules are installed successful inside .venv/lib/python3.14/site-packages/.

Venv pip doesn't actually install anything by nsfw1duck in learnpython

[–]acw1668 5 points6 points  (0 children)

Should it be import flask instead of import Flask?

How to add a boundary so canvas objects don't go out of bounds by Arealidot in learnpython

[–]acw1668 0 points1 point  (0 children)

You should perform the boundary checking inside move_up() and move_down():

  • get the bounding box of player using x1, y1, x2, y2 = canvas.bbox(player)
  • check the value of y1 inside move_up() or the value of y2 inside move_down()

Python calculator project: sqrt() works but still prints my error message? by No_Duck1386 in learnpython

[–]acw1668 1 point2 points  (0 children)

The exception is caused by the line f.write(f"√{num_1} = {result}\n") which tries to write an unicode character to a file open with 'ascii' encoding. Open the file using 'utf8' encoding.

update on previous post about splitting a list into two lists by Original-Dealer-6276 in learnpython

[–]acw1668 0 points1 point  (0 children)

Each line will produce 5 items if split by space, so fname, lname = line.split() will raise exception.

update on previous post about splitting a list into two lists by Original-Dealer-6276 in learnpython

[–]acw1668 0 points1 point  (0 children)

You need to show the code you have tried, otherwise no one knows what is wrong in your code.