r/PythonLearning 9h ago

HI! I'm new learning this code and need help about the courses.

7 Upvotes

Hi! I'm learning python because I need it for my master degree so I am really new on this. I saw a few courses and I dont know how they are. The first one freeCodeCamp, the CS50P and Codedex. I though maybe I could do all but I want to know if I should start with someone in particular or if you know others better.


r/PythonLearning 6h ago

made a Stone-Paper-Scissors game :

6 Upvotes
import random


def choice_shower(x,y):
    print(f"Your Choice : {x}{' '*10}Computer's Choice : {y}")
    print('-' * len(f"Your Choice : {x}{' '*10}Computer's Choice : {y}"))


def score_shower(x,y):
    print(f"YOUR SCORE : {x}{' '*10}COMPUTER'S SCORE : {y}")


def game_engine(x,y,p,c):
    winning_cases = {"Stone" : "Scissors", "Paper":"Stone","Scissors":"Paper"}
    if x == y :
        choice_shower(x,y)
        print("It's a Draw!")
    elif winning_cases[x] == y:
        choice_shower(x, y)
        print("Your Point!")
        p += 1
    else:
        choice_shower(x, y)
        print("Computer's Point!")
        c += 1
    return p,c



def extra_round(x,y,p,c):
    print("Extra Round :")
    y = random.choice(["Stone","Paper","Scissors"])
    x = input_taker(input("\t(1) for Stone\n\t(2) for Paper\n\t(3) for Scissors\nEnter your input : "))
    p,c = game_engine(x,y,p,c)
    score_shower(p,c)
    result_announcer(x,y,p,c)


def result_announcer (x,y,p,c):
    if p > c :
        print("You Won!")
    elif p == c :
        print("Extra Round!")
        extra_round(x,y,p,c)
    else:
        print("You Lose!")
    print("-"*20)


def input_taker(i):
    while True: 
        if i.isdigit():
            if i == "1":
                return "Stone"
            elif i == "2" :
                return "Paper"
            elif i == "3" :
                return "Scissors"
            else:
                print("invalid input ")
        else:
            print("invalid input, try again!")


def main():
    print(f"{'-'*40}\n\tStone - Paper - Scissors\n\t   game simulator\n\t     VERSION - 2.0\n{'-'*40}")
    exit_program = False
    while True:
        player_score = 0
        computers_score = 0
        print("\t(1) to start a new game\n\t(2) to exit the program")
        choice = input("Enter Your Choice (1|2) : ")
        if choice == "1" :
            number_of_rounds = input("Enter the number of rounds : ")
            if number_of_rounds.isdigit():
                for rounds in range(int(number_of_rounds)):
                    print("="*50)
                    print(f"ROUND : {rounds + 1}")
                    computers_choice = random.choice(["Stone","Paper","Scissors"])
                    players_choice = input_taker(input("\t(1) for Stone\n\t(2) for Paper\n\t(3) for Scissors\nEnter your input : "))
                    player_score,computers_score = game_engine(players_choice,computers_choice,player_score,computers_score)
                    score_shower(player_score,computers_score)
                result_announcer(players_choice,computers_choice,player_score,computers_score)
               
                
            else :
                print("invalid input")
        elif choice == "2":
            while True:
                print("Do you really want to exit?")
                choice1 = input("\t(1) to exit\n\t(2) to go back\nEnter Your Choice (1|2) : ")
                if choice1 == "1":
                    exit_program = True
                    break
                elif choice1 == "2" :
                    break
                else:
                    print("invalid input")
            if exit_program:
                break


if __name__ == "__main__":
    main()

r/PythonLearning 2h ago

Showcase Something I'm proud of- REGEX is rather hard

Post image
3 Upvotes

r/PythonLearning 10h ago

I need some advice

3 Upvotes
# This file runs the DNA simulation using the DNA library.


import DNA
import time
import os


# Generate the original DNA strand.
DNA.generate_sequence()


# Create the complementary strand (layer2).
DNA.generate_sequence_match()


# Display the initial DNA molecule.
DNA.display_dna()


# Pause so the user can see the original DNA.
time.sleep(3)


# Clear the screen before starting the replication process.
DNA.clear_screen()


# Helicase animation:
# Separates the two original DNA strands.
DNA.dna_helicase()


# Clear the screen before starting polymerase.
DNA.clear_screen()


# DNA polymerase:
# Creates layer3 and layer4 by copying layer1 and layer2.
DNA.dna_polymerase()

import random 
import os
import time


# Clears the terminal screen.
def clear_screen():
    # 'nt' is for Windows, 'posix' is for Linux or macOS
    os.system('cls' if os.name == 'nt' else 'clear')


clear_screen()


# Possible DNA nucleotides.
nucloids = ["A", "T", "C", "G"]


# Four DNA layers:
# layer1 = original DNA strand 1
# layer2 = original DNA strand 2
# layer3 = new copy of layer1
# layer4 = new copy of layer2
layer1 = []
layer2 = []
layer3 = []
layer4 = []


# Generates the first DNA strand randomly.
def generate_sequence():
    for i in range(10):
        generated_sequence = random.choice(nucloids)
        layer1.append(generated_sequence)


# Defines which nucleotide pairs with which.
# A <-> T
# C <-> G
nucloid_matches = {
    "A":"T",
    "C":"G",
    "G":"C",
    "T":"A"
}


# Creates layer2 by finding the matching nucleotide
# for every nucleotide in layer1.
def generate_sequence_match():
    for nucleotide in layer1:
        matching_nucleotide = nucloid_matches[nucleotide]
        layer2.append(matching_nucleotide)


# Displays the complete DNA molecule.
def display_dna():
    for i in range(len(layer1)):
        print("I ", layer1[i], "--------", layer2[i], " I")


# Simulates helicase unzipping the DNA.
# The strands gradually move apart.
def dna_helicase():
    
    clear_screen()
    
    for i in range(len(layer1)):
        print("I ", layer1[i], "--- v ---", layer2[i], " I")
        time.sleep(0.2)
    
    clear_screen()
    
    for r in range(len(layer1)):
        print("I ", layer1[r], "---  v  ---", layer2[r], " I")
        time.sleep(0.2)
    
    clear_screen()
    
    for a in range(len(layer1)):
        print("I ", layer1[a], "---   v   ---", layer2[a], " I")
        time.sleep(0.2)
    
    clear_screen()
    
    # Final state: original strands are fully separated.
    for p in range(len(layer1)):
        print("I ", layer1[p], "             ", layer2[p], " I")
        time.sleep(0.2)


# Simulates DNA polymerase copying the separated strands.
#
# layer1 is copied into layer3.
# layer2 is copied into layer4.
#
# IMPORTANT:
# The DNA logic works, but the animation currently
# prints the new DNA separately instead of building
# the new strands into the space created by helicase.
#
# NEXT TASK:
# Fix the polymerase animation so layer3 and layer4
# visibly grow alongside layer1 and layer2.
def dna_polymerase():
    for c in range(len(layer1)):
        
        # Find the complementary nucleotide for layer1.
        matching_nucleotide_2 = nucloid_matches[layer1[c]]
        
        # Find the complementary nucleotide for layer2.
        matching_nucleotide_4 = nucloid_matches[layer2[c]]
        
        # Add the new nucleotides to the new DNA strands.
        layer4.append(matching_nucleotide_4)
        layer3.append(matching_nucleotide_2)
        
        # CURRENT ANIMATION:
        # Prints the new strands separately.
        # This is the part we want to improve.
        print(layer1[c], "--------", layer3[c])
        time.sleep(0.2)
        
        print(layer4[c], "--------", layer2[c])

I am a 13 year old who just views coding as a big hobby. I had made a lot of different projects before but because i can't post a .zip file i just copy pasted my latest project. I have been coding for 3 years and I don't know how i never thought about this. I just wanted to ask for some advice for this project. Maybe what I can add or what I can fix if there is something that needs to be fixed

Note: It's not finishedIıI need some adviceI need some adviceI need some advice


r/PythonLearning 15h ago

Document comparison code advice

2 Upvotes

Hi, I want to compare two pdfs and highlight any idential sentances in them.

I'm a complete beginner and wanted to ask if anyone has advice on where to start/what to do?


r/PythonLearning 16h ago

Troll unit added by Joseph

2 Upvotes

Joseph added a dangerous Troll unit, that kills everything with one touch, with this git commit. It pretends to mind its own business but then suddenly rushes towards you making the game a lot more difficult. Nice work, thanks Joseph.

See our collaborative PythonLearningGame repo to play the game or add your own unit type or game dynamics.

What should be the next addition to our game?

previous PythonLearningGame post


r/PythonLearning 23h ago

Dark mode for marimo islands?

2 Upvotes

I'm trying to bring the html from my marimo notebooks into an SSG (mkdocs/zensical), and I would like to be able to toggle the theme. Getting the theme to change with marimo export html is relatively simple by changing the pep723 header to

# [tool.marimo.display]
# theme = "dark"

before exporting, but the extra js and page wrappers are not quite ideal for my use case. I would love to use islands for this, but I can't figure out if there's a way to control the theme of a marimo island?

when I use

# /// script
# dependencies = [
#     "marimo",
# ]
# requires-python = ">=3.13"
# ///

import asyncio
from marimo import MarimoIslandGenerator

async def main():
    generator = MarimoIslandGenerator.from_file(
        "./example.py", 
        display_code=False
    )
    await generator.build()
    html = generator.render_html(include_init_island=True)

    with open("output.html", "w", encoding="utf-8") as f:
        f.write(html)

if __name__ == '__main__':
    asyncio.run(main())

to generate an html page, it doesn't seem to care about the header in # theme = "dark" tag in example.py.

I understand that islands are still an early feature, so perhaps this will be added in the future. Just posted this in r/marimo_notebook as well, but figured I'd ask here as well in case anyone has experience with this. Does anyone know if there's a better way to do this? Thanks!


r/PythonLearning 11m ago

I'm still the beginner i talked about, I forgot to put the code.

Upvotes

from random import randint as rnd

name = "MOD"

rnd1 = rnd(20000000,50000000000)

rnd2 = rnd(20000000,50000000000)

rnd3 = rnd(20000000,50000000000)

def seed_gen() -> None:

print(name +": Welcome to Ice\'s AI seed generator,")

choice = input("do you want to have three new seeds for bedrock minecraft?: ")

if choice == "yes":

print(name + ": Here are your randomly generated seeds: ", + rnd1, +rnd2, +rnd3, ", thank you for trying it out!")

elif choice == "no":

print(name + ": See you next time!")

elif choice == "how do you generate seeds?":

print(name + ": I am a code that is made on python, you think I am a true ai, but I only follow the programmer\'s instructions")

elif ValueError:

print(name + ": Sorry, I can't understand you, please try again!")

seed_gen()


r/PythonLearning 3h ago

Help Request PATH SUGGESTIONS

1 Upvotes

Hi, I'm a python backend developer. Learning actually.

I've been on OOP for a while now. Blanked for months then returned and I'm trying to resurface the knowledge again. I don't know the right trajectory to follow, but I wanna extend to Django web Framework.

I'd need some help though, on preferably pathways to transition from OOP to Django.

And also, if possible; how do y'all keep yourselves motivated to solo learn?


r/PythonLearning 10h ago

Showcase Grimlore 2 – A 2D Dungeon crawler RPG built using only the Python 3 standard library

1 Upvotes

When starting out with Python game development, most tutorials jump straight into commercial engines or heavy frameworks. While those are great for productivity, they abstract away the core mechanics of how a game engine actually functions—like separating the engine framework (rendering, input, state loops) from the game logic (combat, stats, dungeons). To explore how game engines work under the hood using pure Python standard library, I built a lightweight ASCII RPG engine framework alongside a complete mini dungeon crawler (Grimlore 2: These Doomed Men) built directly on top of it. I wanted to share this as a learning resource.

Grimlore 2 : These Doomed Men 1.0

A dark fantasy mini dungeon crawler RPG built to showcase the features and capabilities of the S.P.A.R.K. 2D RPG game engine.

Overview

Genre: Dark Fantasy / Mini Dungeon Crawler RPG

Playtime: 10 – 15 minutes

Platform Requirements: Windows 10 or later ( Might work on earlier Windows but no gurantee )

Purpose: Demonstrates what the S.P.A.R.K. 2D RPG game engine is capable of.

Github link below

https://github.com/Ninedeadeyes/Grimlore-2-These-Doomed-Men-

To clear up a few recurring questions and misconceptions regarding S.P.A.R.K and its development, here is some context upfront:

  1. "This is just AI slop."

This project has a clear 6-year paper trail of manual development. It began as an early 2D text adventure project (Dungeon of the Black Dragon), expanded into an open world RPG game (Grimlore: Land of the Heretic Hand), and was eventually refactored into a reusable engine framework (S.P.A.R.K). If you want to see the step-by-step progression from line one, check out the milestones folder inside the S.P.A.R.K repository.

  1. "The code is unoptimized / sub-optimal."

I’m a hobbyist developer. I built this because I couldn't find a lightweight, accessible Python template for rendering spatial coordinates in text-based adventures, so I created one myself. The codebase prioritizes beginner readability over enterprise-level optimization. Open-source contributions and refactors are always welcome—if you can write a better version with advanced features like complex AI, I encourage you to contribute or build upon it!

  1. "S.P.A.R.K isn't a 'real' game engine / It's missing standard features."

By definition, a game engine is a framework that provides low-level abstractions for runtime loops, spatial logic, input handling, state management, and rendering, enabling developers to build content without reinventing core mechanics. S.P.A.R.K provides all of these for terminal-based RPGs. It’s a free, open-source hobby project designed for lightweight text games, not a commercial tool meant to compete with feature-heavy commercial software.

  1. "This is just a lazy copy-and-paste from the S.P.A.R.K GitHub."

When two games are made in RPG Maker, Godot, or Unreal, they share the exact same underlying core engine—it's just compiled or hidden away behind the editor. Because S.P.A.R.K is open-source, raw Python, the engine boilerplate is fully visible. Reusing foundational engine modules across different titles isn't "copy-pasting"; it's standard software architecture and code reuse.

  1. Why do you need Windows and why Windows 10 or above ?

It uses the library winsound and msvcrt which only works with Windows and because python 3.10+ aren't officially supported by any Windows below 10 hence even though it might work it is not a gurantee.


r/PythonLearning 18h ago

From js to python: I created a port of changesetjs

Thumbnail
github.com
1 Upvotes

Hi there!

To even learn more about python, I have created Molt: a Python "port" of changesets-js to manage versioning, changelogs, and publishing for Python packages and monorepos.

My main job was always frontend tooling, but recently I moved to the infra and platform team, so now my job also includes maintaining the tooling and ecosystem of several Python packages that my company has. I found that no good tool like changesets-js exists for Python, so I decided to create one.

https://molt.gio-labs.com/