r/learnpython • • Aug 24 '26

how to make my code work in minecraft

0 Upvotes

dont question my code too much, i just started python and watched a 1 hour coding with mosh video to understand some of the basics.

all it does is move my mouse around while i hold g. but it doesnt work when i go into minecraft, and i assume, any program that locks my mouse.

what do i do?

import random
import keyboard
import pyautogui
import pyscreeze
from pyautogui import mouseInfo, click
while True:
    if keyboard.is_pressed('g'):
        pyautogui.moveTo(random.randint(0, 2600), random.randint(0, 2600))
    if keyboard.is_pressed('q'):
        break

r/learnpython • • Aug 23 '26

Feedback On Fancy Text Printing

2 Upvotes

I've been learning python for years, but I rarely show my code to anyone. I enjoy showing the results of my code to people, but I don't know too many programmers IRL who can give me feedback. I know I have a habit of not commenting enough, but hopefully this is readable. It's my attempt at making text print like in video games (Earthbound, for example.)

Am I doing anything particularly inefficient? I want to know how I can improve this.

from time import sleep
import sys

#Theoretically there could be other wait times for punctuation
punc_default = {" ": 0, ",": 0.25, ".": 0.4, "!": 0.5, "?": 0.5}

def txt(string,time=0.05,punctimes=punc_default):
    for char in string:
        sys.stdout.write(char)
        sys.stdout.flush()
        if char not in punctimes: sleep(time)
        else: sleep(punctimes[char])

txt("Who lives in a pineapple under the sea? Spongebob Squarepants! qwertyuiop.")

r/learnpython • • Aug 21 '26

Best way to learn python for someone with 0 experience with programming

143 Upvotes

I need help with where to begin learning python. I have 0 experience in programming. So I need all the help I can get. Books, websites and courses(free as I can't afford to pay for anything right now) maybe YouTube tutorials.

But on the subject of YouTube tutorials I've seen it's not good to just follow along with the tutorials so what would be the best way of engaging with tutorials?

Please any suggestion is welcome and thank you very much in advance.

What helps you focus I tend to lose focus easily because my brain just suddenly remembers I have something I need to do when I decide to be productive.

Edit: Thank you guys for your suggestions. They've been very helpful. I see all of your replies; I just can't get to every single one of them, but I see them. Thank you very much.

I'm doing CS50P and also using Automate the Boring Stuff and this other book with small projects. Thank you guys so much.


r/learnpython • • Jun 18 '26

I went to superfastpython.com and saw the author wrote "I don't see the need for the books and tutorials, given the era of LLMs." Am I wrong in thinking books are still very important?

23 Upvotes

I'm learning Asyncio at the moment because I want to understand the code LLMs give me.


r/learnpython • • Jul 13 '25

Looking for Python Crash Course, 3rd Edition PDF šŸ™

25 Upvotes

If anyone has the 3rd edition of Python Crash Course in PDF or EPUB and is willing to share, I’d deeply appreciate it.

Thanks a lot šŸ™


r/learnpython • • Dec 02 '24

Can someone explain to me how do decorators work?

38 Upvotes

I have been coding for quite a while (2-3yrs) and use to mostly just let it go but I need to know how these things work. Also what was the need for this that could not possibly be done without decorator.

p.s. I did try chatGPT I did not understand


r/learnpython • • Oct 10 '24

can someone explain lambda to a beginner?

107 Upvotes

I am a beginner and I do not understand what lambda means. Can explain to me in a simple way?


r/learnpython • • Sep 02 '24

Speech to Text API

4 Upvotes

Hi guys, hope y'all doing well! So, I'm at this group of robotics from my university and we need a API that recognizes voice and transcribes it to text. We're looking for something that can run on a low end pc (like a potato or something like that), if some of y'all knows something good, please share with me! Thank y'all fr the help !


r/learnpython • • Jun 13 '24

Rock Paper Scissors (First Personal Project)

16 Upvotes

Well, you may start seeing me post frequently as I continue to progress in Python! In the previous post I mentioned "project time". I spent a little time to build Rock, Paper, Scissors in a way I know to make it work. Now, that I know that this works, it may be time to refactor it, because the code seemed repetitive and very lengthy, but I want your guys thoughts on it.

==================================================================

# Rock, Paper, #Scissors
import random

choices = ['rock', 'paper', 'scissors']
player_score = 0
computer_score = 0

print('Welcome to Rock, Paper, Scissors!')

while True: 
    #prompt the user to choose between rock, paper, or scissors.
    player_input = input('\nEnter Rock, Paper, or Scissors: ')
    print("Enter 'q' to quit. ")

    # break the loop if player types 'q'
    if player_input.lower() == 'q':
        break

    #computer generate a random choice of rock, paper, or scissors. 
    computer_choice = random.choice(choices)

    # player and computer chooses same option, its a draw.
    if player_input.lower() == computer_choice:
        print('DRAW!')

        # if player chooses rock, and computer chooses paper.
    elif player_input.lower() == 'rock' and computer_choice == 'paper':
        computer_score += 1
        print('Paper covers rock, Computer wins! ')

        # if player chooses rock, and computer chooses scissors.
    elif player_input.lower() == 'rock' and computer_choice == 'scissors':
        player_score += 1
        print('Rock beats Scissors, Player wins! ')

        # if player chooses paper, and computer chooses scissors.
    elif player_input.lower() == 'paper' and computer_choice == 'scissors':
        computer_score += 1
        print('Scissors cut paper, Computer wins! ')

        # if player chooses paper, and computer chooses rock.
    elif player_input.lower() == 'paper' and computer_choice == 'rock':
        player_score += 1
        print('Paper covers Rock, Player wins! ')

        # if player chooses scissors, and computer chooses rock.
    elif player_input.lower() == 'scissors' and computer_choice == 'rock':
        computer_score += 1
        print('Rock beats scissors, Computer Wins! ')

        # if player chooses scissors, and computer chooses paper.
    elif player_input.lower() == 'scissors' and computer_choice == 'paper':
        player_score += 1
        print('Scissors cut paper, Player wins! ')

    else:
        # if computer chooses rock, and player chooses paper.
        if computer_choice == 'rock' and player_input.lower() == 'paper':
            player_score += 1
            print('Paper covers rock, Player wins! ')

        # if computer chooses rock, and player chooses scissors.
        elif computer_choice == 'rock' and player_input.lower() == 'scissors':
            computer_score += 1
            print('Rock beats Scrissors, Computer wins! ')

        # if computer chooses paper, and player chooses scissors.
        elif computer_choice == 'paper' and player_input.lower() == 'scissors':
            player_score += 1
            print('Scissors cut paper, Player wins!')

        # if computer chooses paper, and player chooses rock.
        elif computer_choice == 'paper' and player_input.lower() == 'rock':
            computer_score += 1
            print('Paper covers Rock, Computer wins!')

        # if computer chooses scissors, and player chooses paper.
        elif computer_choice == 'scissors' and player_input.lower() == 'rock':
            computer_score+= 1
            print('Scissors cut paper, Computer wins! ')
        # if computer chooses scissors, and player chooses paper.
        elif computer_choice == 'scissors' and player_input == 'paper':
            computer_score += 1
            print('Scissors cut paper, Computer wins! ')


# print total score. 
print ('\nGAME OVER!')
print (f'Player Score = {player_score} Computer Score = {computer_score}')
if player_score > computer_score:
    print('Player wins the game!')

elif player_score == computer_score:
    print('DRAW!')

else:
    print('Computer Wins the game!')

r/learnpython • • Oct 10 '23

Best way to Create responsive Modern GUIs in Python ?

18 Upvotes

In my opinion PyQt5 (or pyside6 no difference i think ) is the best option because it has its own QT designer + Ide but I dont how we can make it more modern ,

I m building a windows app as a side project i need some suggestions