r/learnpython • • 3d ago

Little fun code I put together:)

Edit: I fixed the last line in the program, just had an issue when pasting it and didn't think when I filled it back in. Thank you guys for letting me know!

Hi! So I've been learning code for a little while now and lately, I've been getting more ideas for little programs to put together. They're not really useful in practical sense, but they're still fun exercises and ways to challenge myself while I'm still learning and understanding the basics.

I just thought this one would be fun to share because it took me a second to figure out the best way to have both lists be printed at the same time. Honestly though, I don't know why I didn't think of just doing a function right away though HSDH

The basic idea of the program is to generate a full breakfast by randomly choosing an entree and a side to go with it!

import random

entree_list = ["eggs", "cereal", "waffles", "oatmeal"]

side_dish = ["hashbrowns", "toast", "orange", "banana", "yogurt"]

def breakfast_run():
    print("Get someeeeeee")
    print(random.sample(entree_list, k=1))
    print("and")
    print(random.sample(side_dish, k=1))

breakfast_run()
0 Upvotes

11 comments sorted by

5

u/ninhaomah 3d ago

" print(breakfast_run()"

Have you tried running it ? Aren't you missing something ? Or copy/paste issue ?

0

u/V0xter 3d ago

OH oops sorry I don't know why I wrote that Yeahhh it was a copy/paste issue, I just spaced out when I filled it back in HSHDH lemme fix that

0

u/FontanJanneice18 2d ago

yeah looks like op edited it, definitely was just a copy paste typo

4

u/smichaele 3d ago

This definitely won’t run as shown.

-1

u/V0xter 3d ago

Aghhh yeah I just had a copy/past issue and it didn't put in the last line, and I spaced out when I put it back in HSHD

2

u/Riegel_Haribo 1d ago

Little fun code mixing the items into one list, where the even items are main dishes that come first.

from random import choice

menu = [
    "hashbrowns", "eggs",
    "toast", "cereal",
    "orange", "waffles",
    "banana", "oatmeal",
    "yogurt",
]

print(" and ".join(choice(menu[i::2]) for i in (1, 0)))

It uses list slicing, iterating in steps of 2 items from a start index.


A little trick you can do with your own code is to use: print("my string", end="")

That "end" replaces the normal linefeed after each print with no additional character, so the cursor caret stays on the same line for the next print().

1

u/V0xter 1d ago

OOHH Okayyy! I'll have to play around with this soon..

2

u/SnooHedgehogs52 3d ago

I like it, it’s cute.

Great work homie!

2

u/V0xter 2d ago

Thank youu!!

1

u/Chris_Charley 2d ago

You could use `random.choice(entree_list)` here as it returns 1 random selection from the list. (Same for `side_dish`)

1

u/V0xter 2d ago

True!! I'll look into that when I've got a minute