r/learnpython • • Feb 12 '24

Day 2 of learning python. I made the most complicated code I could that counts to 10

counter = 0

while counter < 5:

 counter += 1

 print(counter)

if counter < 5:

 function = True

if True:

  print(6)

if True:

  dex = 5

while dex < 6:

  dex += 1

  print(7)

if dex <= 6:

  print(8)

if dex <= 6:

  hp = 5

while hp > 4:

  hp -= 1

  print(9)

if hp >= 4:

  fax = 10

if fax != counter:

  print(10)
2 Upvotes

13 comments sorted by

6

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Feb 12 '24

I don't really see the point, but good for you!

The indentation is broken, though. I'm assuming this is what you meant.

counter = 0

while counter < 5:
    counter += 1
    print(counter)

if counter < 5:
    function = True

if True:
    print(6)

if True:
    dex = 5

while dex < 6:
    dex += 1

    print(7)

    if dex <= 6:
        print(8)

if dex <= 6:
    hp = 5

while hp > 4:
    hp -= 1

    print(9)

if hp >= 4:
    fax = 10

if fax != counter:
    print(10)

9

u/Shut_up_and_Respawn Feb 12 '24

I started learning coding and just wanted to see what I could do; mainly experimenting with while loops and if functions.

And yeah, that is how I had it; I think copy and pasting it into reddit just messed up the indentations

19

u/Invader_Mars Feb 12 '24

“Just wanted to see what I could do”

10/10 mindset

3

u/Shut_up_and_Respawn Feb 12 '24

I dont have anything purposeful to code, so I just do it for fun. Play around and experiment. I could have written that whole thing in 4 lines if code, but did it in 24 instead. Its fun overcomplicating things

3

u/flower_power_g1rl Feb 12 '24

It's awesome! You learned so much I can't believe this is just your second day! What's your next project?

2

u/Shut_up_and_Respawn Feb 12 '24

That is a great question. I have no idea though. I might try to make myself a personal coding glossary with the definitions of terms and examples of common code blocks like while loops

1

u/_Cline Feb 12 '24

How do you indent on reddit?

1

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Feb 12 '24

In this subreddit the recommended way to create a code block is by adding four spaces before each line of code. Protip: you can just select your code in your editor, add an extra level of indentation (assuming spaces, tab characters won't work) and copy-paste that, reverting the editor changes afterwards.

Inside a code block, indentation works like normal.

You can technically alternatively wrap your code in triple backticks, but that doesn't work for Old Reddit which most of our regulars use so while that's common in other subreddits we prefer the method that works for everyone.

3

u/moving-landscape Feb 12 '24

Tip: if True is as good as no if block at all. You don't need the extra level of indentation.

1

u/Shut_up_and_Respawn Feb 12 '24

I know, Im just trying make it complicated

1

u/moving-landscape Feb 14 '24

I see now what you were trying to do.

Hey, why not use some variables since the goal is to unnecessarily complicate it? In place of if True, how about

enter_this_block = True

if enter_this_block:
    # increment count
    skip_this_block = False

if not skip_this_block:
    # ...

1

u/Shut_up_and_Respawn Feb 14 '24

The reason is because I hadnt gotten to that point of learning yet. In that program, I was just trying to use the things I knew as much and in as many different ways as possible. I still have not learned that stuff yet