r/code • • Nov 20 '25

Python Rate my first ever fully working python code lol

5 Upvotes
# fortune_1_test


# fortune dictionary
import random
fortune = [
    "Billy-Bob will be under your bed today! watch out!",
    "Freaky franky will be under your bed today!",
    "Phreaky sophi will be under your bed to day!",
    "Adam will suck your toes off today!",
    "Hungry Hunter will suck your toes off!",
    "freaky zyan will eat your toothbrush today!", ]


# fortune generator
print(random.choice(fortune))


# loop
while True:
    input("press enter to get your fortune!... or press cntrl+c to exit!")
    print(random.choice(fortune))
    print()

did this in like 30 mins cuz i was bored!

r/code • • Oct 20 '26

Python Add 0.1 ten times in Python and you miss 1.0

Thumbnail
youtube.com
2 Upvotes

r/code • • Nov 06 '25

Python Secret

1 Upvotes

# Caesar-cipher decoding puzzle

# The encoded message was shifted forward by SHIFT when created.

# Your job: complete the blanks so the program decodes and prints the message.

encoded = "dtzw izrg" # hidden message, shifted

ALPHABET = "abcdefghijklmnopqrstuvwxyz"

def caesar_decode(s, shift):

result = []

for ch in s:

if ch.lower() in ALPHABET:

i = ALPHABET.index(ch.lower())

# shift backwards to decode

new_i = (i - shift) % len(ALPHABET)

decoded_char = ALPHABET[new_i]

# preserve original case (all lowercase here)

result.append(decoded_char)

else:

result.append(ch)

return "".join(result)

# Fill this with the correct shift value

SHIFT = ___

print(caesar_decode(encoded, SHIFT))

r/code • • Aug 25 '24

Python python code help!

4 Upvotes

Traceback (most recent call last):

File "C:\Users\"Username"\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\ext\commands\core.py", line 235, in wrapped

ret = await coro(*args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\"Username"\Codes\Kama\main.py", line 40, in join

await channel.connect()

File "C:\Users\"Username"\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\abc.py", line 1958, in connect

voice: T = cls(client, self)

^^^^^^^^^^^^^^^^^

File "C:\Users\"Username"\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\voice_client.py", line 220, in __init__

raise RuntimeError("PyNaCl library needed in order to use voice")

RuntimeError: PyNaCl library needed in order to use voice

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "C:\Users\"Username"\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\ext\commands\bot.py", line 1366, in invoke

await ctx.command.invoke(ctx)

File "C:\Users\"Username"\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\ext\commands\core.py", line 1029, in invoke

await injected(*ctx.args, **ctx.kwargs) # type: ignore

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "C:\Users\"Username"\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\ext\commands\core.py", line 244, in wrapped

raise CommandInvokeError(exc) from exc

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: RuntimeError: PyNaCl library needed in order to use voice

I use visual studio code as my ide i have the PyNaCl install but the !join code dont work

here the code that i want to run

@client.command(pass_context = True)
async def join(ctx):
    if(ctx.author.voice):
        channel = ctx.message.author.voice.channel
        await channel.connect()
    else:
        await ctx.send("No Channel to connect")
        
@client.command(pass_context = True)
async def leave(ctx):
    if(ctx.voice_client):
        await ctx.guild.voice_client.disconnect()
        await ctx.send("Leaving")
    else:
        await ctx.send("Not in voice channel")

when i call the bot to join the voice chat this error pop up instead

r/code • • May 12 '26

Python Basic Text-Based RPG

6 Upvotes

I made a basic Text-Based RPG (Around 200-300 lines) and was hoping someone could give me their opinion on it (the game less then 20 minutes long, and the dragon is as far as I've developed so far)
https://onlinegdb.com/thxBEi9V3
Enjoy : )

r/code • • Jan 31 '26

Python I made a creative Git CLI that turns your repo into a garden

Thumbnail
gallery
12 Upvotes

Although I've been coding for many years, I only recently discovered Git at a hackathon with my friends. It immediately changed my workflow and how I wrote code. I love the functionality of Git, but the interface is sometimes hard to use and confusing. All the GUI interfaces out there are nice, but aren't very creative in the way they display the git log. That's why I've created GitGarden: an open-source CLI to visualize your git repo as ASCII art plants. GitGarden runs comfortably from your Windows terminal on any repo you want.

**What it does**

The program currently supports 4 plant types that dynamically adapt to the size of your repo. The art is animated and procedurally generated with many colors to choose from for each plant type. I plan to add more features in the future!

It works by parsing the repo and finding all relevant data from git, like commits, parents, etc. Then it determines the length or the commit list, which in turn determines what type of plant will populate your garden. Each type of plant is dynamic and the size adapts to fit your repo so the art looks continuous. The colors are randomized and the ASCII characters are animated as they print out in your terminal.

**Target Audience**

Intended for coders like me who depend on Git but can't find any good interfaces out there. GitGarden makes learning Git seem less intimidating and confusing, so it's perfect for beginners. Really, it's just made for anyone who wants to add a splash a color to their terminal while they code :).

If this project looks interesting, check out the repo on Github: https://github.com/ezraaslan/GitGarden. This contains all the source code.

Consider leaving a star if you like it! I am always looking for new contributors, so issues and pull requests are welcome. Any feedback here would be appreciated, especially in terms of the ASCII art style.

r/code • • Mar 30 '22

Python My sassy/aggressive Error messages

Thumbnail
gallery
22 Upvotes