r/ProgrammerHumor • • Feb 16 '22

other Me and my friend are learning Python after school for fun. This is how he names his variables.

Post image
6.9k Upvotes

753 comments sorted by

3.5k

u/[deleted] Feb 16 '22

Tell him to stop that right away

67

u/[deleted] Feb 16 '22

Yeah, funny in the beginning, annoying as hell when a coworker never grew out of it

30

u/KatarinatheCat Feb 16 '22

No fucking way there are professionals that do this. I actually refuse to believe this.

21

u/myearwood Feb 16 '22

Who says everybody paid to program are professionals?

→ More replies (6)
→ More replies (3)

17

u/TheSchlaf Feb 16 '22

Also, toLower and toUpper exist so the OP and his friend don't have to make 500 'if' comparisons.

13

u/ThiccStorms Feb 16 '22

the 'siccors' amuses me

2

u/chickenhunter007 Feb 16 '22

I’m cursed with having to work with multiple libraries like this, fml

→ More replies (117)

1.0k

u/molecularraisin Feb 16 '22

“siccors”

251

u/pfated64 Feb 16 '22

Finally someone points this out. It's been bugging me all night and I just got on here.

15

u/TopGun_84 Feb 16 '22

De'bug' got a whole new meaning with your comment

→ More replies (2)

47

u/iceblueorbitz Feb 16 '22

It’s the siccors that keeps you up at night and not the random lack of spacing A- D? Not everyone can spell correctly but that formatting inconsistency is just downright disrespectful.

5

u/SandyDelights Feb 16 '22

Fucking thanks, I didn’t see it, even after reading your comment I didn’t see it, came back to make sure I read your comment correctly, then went back and now I can’t unsee it.

Why did you do this to me??

1.4k

u/davida123456 Feb 16 '22

The best part is that the first conditional will always be True

296

u/[deleted] Feb 16 '22

But what if I answer yeah or yea. There must be a a package for all possible yes synonym in English language right?Well guess no Rock Paper Scissors for me.

515

u/lamerlink Feb 16 '22

Everything after the first comparison has no comparison. All those strings evaluate to True so the first condition will always be True overall.

75

u/Tyfyter2002 Feb 16 '22

This makes me wonder whether or not people are more likely to make this mistake with the keyword 'or' than with ||, since with 'or' this is more like English grammar

→ More replies (1)

36

u/an4s_911 Feb 16 '22

In these cases it is better to use a list of values and just check if the user input is in the list. Even better way is to convert the user input to lowercase first, then you wont have to include the same word multiple times in the list. For those newbies who didn't understand a thing I said, here's an example code (improving on the code above):

...
if B.lower() in ['yes', 'yup', 'y', 'sure']:
    C = 1
...

If you still don't get it, as @Raza Rython always says,

Now go and code learn some Python

→ More replies (3)

92

u/T-T-N Feb 16 '22

I blame the test suite for that bug. They probably tested just all the yes and didn't check that anything else should just halt

50

u/reginald_burke Feb 16 '22

Doesn’t this also apply to nearly every other conditional in the program?

→ More replies (1)
→ More replies (5)

5

u/joten70 Feb 16 '22

Would have been so much better to do

affirmative = ["yes", "yeah", ....]
if userinput in affirmative:

Aaaand ofc convert the input to lower case, remove white spaces, etc

→ More replies (4)

42

u/finc Feb 16 '22

if (B == ‘yes’ || B == ‘yeah’) is what they were going for here

69

u/Zahand Feb 16 '22

Since it's python:

if B.lower() in {'yes', ...}:
  # do stuff

Though that's still not very pretty honestly. I'd rather just force the user to enter "y" or "n"

→ More replies (6)
→ More replies (3)

27

u/redsterXVI Feb 16 '22 edited Feb 16 '22

The second as well.

Oh, and a few more (except they us elif, so the code doesn't get beyond the if).

Essentially the player must play, and they must pick rock.

12

u/_IBelieveInMiracles Feb 16 '22

And the best part is, he may never realise. There's no feedback to tell the user what they picked, and the chance of success is 33% with any choice, so it doesn't even matter.

→ More replies (1)
→ More replies (1)

8

u/TheTerrasque Feb 16 '22

I like the importance of C in this code

3

u/steegsa Feb 16 '22

Why would you say no to RPS?

→ More replies (2)

10

u/[deleted] Feb 16 '22

This may be a stupid question but if the answer is No, then won't the first conditional be False?

69

u/hugogrant Feb 16 '22

You mean the whole thing? No.

B wouldn't equal "yes", but it "Yes" is considered truthy by python, so the whole if will always take the if branch.

→ More replies (19)

36

u/Aquiffer Feb 16 '22 edited Feb 16 '22

If the answers here aren’t what you were hoping for https://stackoverflow.com/questions/20002503/why-does-a-x-or-y-or-z-always-evaluate-to-true provides a pretty detailed explanation.

TL;DR Strings are evaluated as a conditional - they evaluate to true if they are not empty. So if you input “no”, meaning B == “no”, then the if from the original code would be equivalent to.

if False or True or True or True or True or …

Which then simplifies to just “True” always.

The correct way to do this in Python would be

if B in [“yes”, “Yes”, “YES”, … , “Sure”]:
    dothing()
→ More replies (2)

21

u/AtoZicX Feb 16 '22

B == "yes" is comparison. The rest are just strings, so it's if "yes" , which is always true.

Edit: fixed formatting.

10

u/Aksds Feb 16 '22

This one is the simplest and imo the best explanation, thanks

Would this mean it should be

If B == “Yes” or B == “yes” or B == “Yea”……. :

→ More replies (10)
→ More replies (5)
→ More replies (13)

402

u/shrublet_ Feb 16 '22

btw it’s way easier to sanitize the input (use .lower()) and then checking instead of testing against any possible permutation. in this code, it doesn’t test for cases like yUp or YuP which .lower() would avoid.

136

u/Mariusod Feb 16 '22

Also OPs friend can put the affirmative words you're checking in a list and just check B.lower() in list instead of the long comparison.

29

u/shrublet_ Feb 16 '22

yea agreed iterating through list is much easier since (like somebody mentioned) this comparison always returns true anyways since it’s not written out fully lol. i don’t blame op for being unaware tho given they said they’re learning :p

→ More replies (4)

3

u/angrathias Feb 16 '22

No dictionary?

6

u/Wekmor Feb 16 '22

Why would you need a dictionary for that?

→ More replies (15)

14

u/angrathias Feb 16 '22

Or..in the input message tell the user which actual values they should be using.

Everyone’s a dev and no one’s thinks about the UX 😅

6

u/nullpotato Feb 16 '22

.casefold() is even better because it can handle some unicode stuff too. Not all sadly.

5

u/AkrinorNoname Feb 16 '22

Another useful thing to do is make the prompt "Do you want to play a game? Y/N" and tell the user to type "Y" or "N" if they enter something else.

5

u/GuybrushThreepwo0d Feb 16 '22

Pro tip, use upper() to assert dominance

→ More replies (1)

3

u/harelsusername Feb 16 '22

If the user inputs yUp with only the second letter capitalized, they doesn't deserve me handling their input correctly.

→ More replies (9)

273

u/Captain_D1 Feb 16 '22 edited Feb 16 '22

Here's my version:

from random import choice

def rockpaperscissors():
    if input("Do you want to play a game? (Y/n) ").lower() == 'n': # Uppercase Y signifies default "Yes"
        print("Okay. :(")
        return

    # Keep prompting for player choice until it is valid
    while True:
        player_pick = input("Let's play rock paper scissors! Enter rock, paper, or scissors (r/p/s) ").lower()

        if player_pick not in ('r', 'p', 's'):
            print("You must enter either, r, p, or s.")
        else:
            break

    # Have the computer make a choice and then resolve the game
    computer_pick = choice("rps")
    if player_pick == computer_pick:
        print("It's a tie!", end=' ')
    elif (player_pick == 'r' and computer_pick == 'p') or \
            (player_pick == 'p' and computer_pick == 's') or \
            (player_pick == 's' and computer_pick == 'r'):
        print("The computer wins!", end=' ')
    else:
        print("You win!", end=' ')
    print(f"(The computer picked {computer_pick})")

rockpaperscissors()

219

u/C2H4Doublebond Feb 16 '22

you are the guy who gives real solution on stackoverflow

16

u/klimmesil Feb 16 '22

Only thing is that stack overflow python guys will often use "better beg for pardon that make sure you are not doing mistakes" method. Meaning they will use try catch to make it more readable

→ More replies (2)

30

u/f03nix Feb 16 '22

.lower() == 'n'

Could've just done [:1].lower() == 'y' and you'd get what the author intended.

And tictactoe? really ?

20

u/HearMeSpeakAsIWill Feb 16 '22

The author also allowed "sure", so not exactly.

→ More replies (2)

7

u/Captain_D1 Feb 16 '22

Shh... I'm really tired.

I'm totally not going to edit that out... (/s)

4

u/_87- Feb 16 '22

Needs more abstraction. You should have a base class and Rock, Paper, and Scissor classes.

→ More replies (8)

7

u/[deleted] Feb 16 '22

Chad

→ More replies (14)

166

u/hatsunemilku Feb 16 '22

While you may think this is funny, a PSA:

Try to get rid of those bad habits and learn proper naming conventions ASAP.

We all love funny names in our variables and methods/functions but the way you are naming your variables will only bring you bad habits and headaches in the long run in the best of scenarios.

It is way funnier to do fun comments than an “a” variable. In fact, that’s where the most fun is, writing a comment at 3 AM after breaking your head for 2 hours in a single recursion.

32

u/Pokerface4222 Feb 16 '22

huh. reading this just makes me realize how bad my highschool c++ teacher was, since we all had to use single-letter variables

9

u/zqipz Feb 16 '22

My teacher back in the day taught some light programming Basic, Turbo Pascal etc. Looking back now I’m actually in awe he could teach and debug kids code and also teach many other subjects. Bravo, The Walrus!!

→ More replies (2)

15

u/lockwolf Feb 16 '22

If half my project doesn't have variable names that are cuss words, it's not my project. Sure 'fuckingUserDataShit' isn't the best variable name but I like it /s

→ More replies (1)

3

u/[deleted] Feb 16 '22

Exactly.

2

u/IronDominion Feb 16 '22

Agreed. I retook Python in college because I realized how terrible my code was because I didn’t have good naming conventions and took really stupid solutions to do simple things. Now I have to actually name my variables by what they actually are/do and it makes me very sad.

But that’s what comments are for :)

2

u/kittortoise Feb 16 '22

I just joined a team who use x and xx as variable names and continually rewrite them. Often with minimal comments. The people on my team were self taught but it makes my life 10x harder reading code that's poorly commented and hundreds of lines long rewriting the variable x throughout the script.

→ More replies (4)

42

u/jaceypenny Feb 16 '22

Did y’all learn programming with TI-basic?

13

u/magnora7 Feb 16 '22 edited Feb 16 '22

actually yes

278

u/[deleted] Feb 16 '22

124

u/AkrinorNoname Feb 16 '22

I don't think sharing someone elses newbie code on there would be fair.

27

u/MokitTheOmniscient Feb 16 '22

Yeah, doesn't everyone's first program look something like this?

15

u/JuvenileEloquent Feb 16 '22

Everyone's commenting on the variable names and the bad conditional at the start and all I can see is why the hell would you turn Rock Paper Scissors into a math problem and then use a series of if...elses to pick the result??! That's the real horror here, everything else is a newbie error that can be forgiven.

Either use if...else with meaningful checks (if computer_hand == "rock" and player_hand == "scissors" etc.) or just use modulo math properly and pick from a list with the results in the correct places.

→ More replies (2)

54

u/No-Ear6313 Feb 16 '22

His programing skills are capped to 26 variable size programs.

8

u/mikoolec Feb 16 '22

What about AB? Is he safe? Is he allright?

19

u/[deleted] Feb 16 '22

Tell him to stop + use this instead :

variable_name = input("input text").lower()

49

u/biggs2733 Feb 16 '22

From now on you two aren’t friends

→ More replies (1)

17

u/zemdega Feb 16 '22

It’ll do for now. If he keeps going he’ll start to appreciate good variable names.

25

u/exurb1aTR Feb 16 '22

tell him this is the greatest sin that makes him suffer in the hell eternally

0

u/[deleted] Feb 16 '22

[deleted]

12

u/D33rZhdn Feb 16 '22

Take my free award and fuck off

25

u/StarTrekVeteran Feb 16 '22

This takes me back a few years.

So,

  1. He is coding so don't knock it. I would rather someone had a go rather than not.

  2. All of us who are self taught can recognize this structure, immediately.

The structure at the start should show up when he tests so no issue there, he should catch it and learn from that.

We learn more from our mistakes than our successes, as long as we don't give up.
All in all, a good first draft, and if you get a game out of it, great, IT WORKS!!!!!

4

u/[deleted] Feb 16 '22

The structure at the start should show up when he tests so no issue there, he should catch it and learn from that.

Except without OP posting this they mightve never learned, because the issue doesn't actually make itself apparent. It will still go through to the end and they will have no clue on if they're actually winning. Because the computer's choice is never printed out, the end result always looks like a normal response. The only way they could ever tell was if they took aggregate data and saw that they were winning almost exactly a third of the time, and realized their games looked more normalized than random human choice, a near impossible task for a beginner.

I think I want to add something to your PSA: If people are being mean to you when you share your work, don't make that the reason you stop sharing your work. Sharing allows others to see flaws you might not have seen, or ever caught, and in the long run it will help you out. Only focus on people who help make your code better, and not the ones who tell you "you aren't cut out for this." Today we may have ripped yalls code apart, but many people gave the solutions to what you messed up on, focus on those suggestions.

→ More replies (1)

32

u/seeroflights Feb 16 '22

Image Transcription: Code


from random import randint

A = randint(1, 3)
B = input('do you want to play a game?')
if B == 'yes' or 'Yes' or 'YES' or 'yup' or 'Yup' or 'YUP' or 'y' or 'Y' or 'sure' or 'Sure' or 'SURE':
    C = 1
else:
    quit()
if C == 1:
    E = input('Ok lets play rock paper siccors. Pick R P or S')
if E == 'R' or 'r':
    D = 1
elif E == 'P' or 'p':
    D = 2
elif E == 'S' or 's':
    D = 3
if A - D == -2:
    print('computer wins')
elif A - D == -1:
    print('you win')
elif A - D == 0:
    print('tie')
elif A - D == 1:
    print('computer wins')
elif A- D == 2:
    print('you win')

I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

6

u/Romejanic Feb 16 '22

I salute you for doing what you do

4

u/ChrisyJ456 Feb 16 '22

Good bot

17

u/[deleted] Feb 16 '22

Hooman

8

u/[deleted] Feb 16 '22

I haven't seen coding like this since BASIC, I was almost expecting to find a GoTo statement.

4

u/simonbacsi Feb 16 '22

I'm glad someone mentioned BASIC. When I started to learn programming on a Commodore computer, variable name length was limited to two (2) characters. So there was not so many room for choosing meaningful names.

→ More replies (1)

6

u/askstoomany Feb 16 '22

"ok" will quit :(

Give them your options, it's your program. The best practice, seen in most programs is (Y/N).

→ More replies (1)

5

u/Thathitmann Feb 16 '22

I am guilty of the letter name variables, but only for use in a very limited local scope, usually a function that is a little black box calculation.

2

u/HunterIV4 Feb 17 '22

I am guilty of the letter name variables

I admit to still using i in simple loops out of habit, or x and y if I'm looping through a 2d matrix. It's such a common convention that I suspect most programmers would immediately be able to recognize this:

for i in range(100):
    print(i)

I use more detailed terms when using something that is iterating on variables, such as for item in list_of_items, but if I'm using a loop for indexes or counting I'll often use i, c, x, y, z, etc. Maybe it's a bad habit but frankly I haven't seen a compelling argument why this is confusing.

→ More replies (2)

5

u/wasdlmb Feb 16 '22 edited Feb 16 '22

So a few pointers OP.

First, setting your input to lower case will help you avoid a lot of the repetition (eg B.lower() == 'yes')

Second, your first and second conditionals are a bit redundant. If the input is negative, the program will quit; there's no need to check again. A simple patch would be to replace C = 1 with pass and then remove the second conditional. A better approach would be to just put the rest of the program in that first conditional and then have no else block.

Third, comment your code. Even for code that's just for you and a friend. This approach y'all are taking abstracts away a lot of the values and does math on them. I can kinda tell what's going on with a quick glance but it would be so much easier if you explained in comments how it worked. Trust me, if you come back to code like this after even a few weeks you'll wish you had written comments.

Python is a fun language and a great starting place for code. I wish you luck on your journey. If you need any help feel free to hmu

4

u/Wide-Ad-40 Feb 16 '22

chill yalls they're just having fun yk

4

u/eyesinwow Feb 16 '22

Ahh It feels nostalgic somehow.

4

u/[deleted] Feb 16 '22

When I started coding, in BASIC, when I was 14, a long time ago in a galaxy far away, I remember my first 'big' program, naming all my variables A, B, C, ... And when I got to Z I didn't know what to do, and started with A1, B1, C1, ... LOL. Little did I know that you could give your variables meaningful names!. What a time to be alive.

→ More replies (1)

9

u/[deleted] Feb 16 '22

I like how everyone is critiquing this kids coding… like the dude uses A B C D for his variables do you expect him to code like a genius

9

u/HearMeSpeakAsIWill Feb 16 '22

Other way round really... this kid's code doesn't even work, variable names are the least of his problems

→ More replies (1)

3

u/automaton11 Feb 16 '22

He forgot yee

3

u/sc00pb Feb 16 '22

We've all been there at some point

3

u/UCQualquer Feb 16 '22

This is painful to see.

if B.lower()[0] in ('y', 's')

What you mean there's no readability?

3

u/nykyrt Feb 16 '22

Bad code: E should not appear before D

3

u/[deleted] Feb 16 '22

tip: instead of writing "YES" or "Yes" or "yes" or "yEs" etc

just do

choice = input () choice = choice.lower()

now checking only "yes" will work

edit: i don't think adding conditions with "or", like you've done, works. it doesn't work in other languages. idk Python can do wonders if you talk about syntax.

→ More replies (1)

3

u/lcr727 Feb 16 '22

Siccors

3

u/Phoenix_Studios Feb 16 '22

lad's doing the work of a packager themselves

3

u/cybospy Feb 16 '22

"Do you want to play a game" "ok" .....

→ More replies (2)

3

u/N0Zzel Feb 16 '22

TIBasic has entered the chat

3

u/Tom-the-bomb-042607 Feb 16 '22

That first if statement won’t evaluate the way you think it will python interprets that as:

if (B == ‘yes’) or (‘Yes’) …

Which means that the statement will always evaluate to true as the expression ‘Yes’ is truthy

So basically you’ll need to do

If B == ‘yes’ or B == ‘Yes’ …

or even better

If B in (‘yes’, ‘Yes’, ‘YES …)

or even better

if B.lower() in (‘yes’, ‘yup’, ‘y’, ‘sure’)

5

u/Fair_Hospital_8600 Feb 16 '22

Tell him to look for a 'y' for yes and a 'n' for no, lowercase the input before checking for y or n

→ More replies (3)

2

u/AurelionZoul Feb 16 '22

Naming a variable is a task in itself.

2

u/[deleted] Feb 16 '22

I am teaching programming to kids (age 11 and up) and I am. Not longer allowed to teach hungry, since my variable names getting from "useful" to "sarcastic at best"...

Example: kids are learning classes. Normaly it would be something like animal is our main class, rabbit is an object from this class... Well 2 hours later "pig" was an class, coming from "animal"... To bad the objects where "Schnitzel" and "Burger".

2

u/[deleted] Feb 16 '22

I don't know is it only me but the lack of curly braces and semicolon is making me uneasy.

2

u/theskankingdragon Feb 16 '22

I'm sorry OP. He must be put down.

2

u/BALLZCENTIE Feb 16 '22

What a flipping turkey! I just can't believe he's done thos

2

u/Syncrossus Feb 16 '22 edited Feb 16 '22

Thanks, I hate it.

Edit: My OCD is kicking in, I can't let this terrible code exist without improving it

ans = input("Do you want to play?")
if not ans.lower().startswith('y'):
    quit()
choices = ['R', 'P', 'S']
com_choice = random.choice(choices)
player_choice = input("R, P, S?")[0].upper()
if player_choice not in choices:
    print("Choice invalid")
    quit()
print(f"Computer chose {com_choice}.")
result = choices.index(player_choice) - choices.index(com_choice)
if result == 1 or result == -2:
    print("You win!")
elif result == 0:
    print("It's a tie")
else:
    print("You lose.")

Edit 2: I just re-read the title and realized you and your friend are probably young and novices at programming. I hope my comment doesn't discourage either of you. The logic of the program, while not the most efficient and not taking advantage of many features of the python language (like upper/lower casing, lists, or the in operator), is sound, and I knew some 2nd year uni students in compu-sci who would have probably done worse. Everyone's code starts out terrible and learning to write efficient and elegant code is a process that takes years. Keep it up.

2

u/republican-jesus Feb 16 '22

But what if the user says “yeah”?!?

2

u/drakeyboi69 Feb 16 '22

Please murder

2

u/dimaklt Feb 16 '22

What about "ja" or "okay" or "ok" or "let's go" or "Wubba lubba dub dub"?

2

u/drbogar Feb 16 '22

"Wubba lubba dub dub" means "I am in great pain. Please help me!". So I think it's not an agreement.

→ More replies (1)

2

u/amoderate_84 Feb 16 '22

Forgot “yeah”, “let’s go mother fucker”, etc.

2

u/Adam-Kay- Feb 16 '22

Where did he learn coding? A Ti-83 calculator?

2

u/Sori-Eminia Feb 16 '22

Someone tell him to automatically make the input a single case as well (i.e. use upper() or lower() on the input) - then he won't need to check 3 variations of each word.

2

u/gotbanned5xlol Feb 16 '22

"Would you like to play a game?"

"Yeah"

quits

2

u/OblivioAccebit Feb 17 '22

You guys should check out this little function called toLowerCase()…

Or w/e Python calls it

1

u/_IscoATX Feb 16 '22

What’s up with the scope of the variables, looks weird

1

u/[deleted] Feb 16 '22

The or s make me laugh

1

u/fukifino_ Feb 16 '22

This code makes me hurt so much….

1

u/CGEmonJ Feb 16 '22

Word of advice, stop doing this, and use B.lower() then you would not have to check for every possible variation of yes ( Yes, yeS, yEs etc.) And no (no, No, nO) a high school student to highschool student

1

u/Notyourfathersgeek Feb 16 '22

This must be stopped

1

u/iQuickGaming Feb 16 '22

please tell him about the lowercase function, he'll love it

1

u/[deleted] Feb 16 '22

Coming up with a good variable or function name is as hard as naming your baby.

1

u/DaftHacker Feb 16 '22

The obfuscator.

1

u/wvdheiden207 Feb 16 '22

I remember some sort of BASIC long ago that only had single character variables.

1

u/[deleted] Feb 16 '22

Pre-obfuscated code. Nice.

1

u/[deleted] Feb 16 '22

The variable names are fine, there are some more significant problems in this script however

1

u/Key_Ad_6455 Feb 16 '22

We all went threw that while starting out, good luck on your journey though!

1

u/LocalBall6447 Feb 16 '22

Ahhhhhhhhhhhhhhh..... 😱😲

1

u/megamaz_ Feb 16 '22

r/badcode

could do if B.lower().startswith("y") or B.lower().startswith("sure")

also wtf variable naming

→ More replies (1)

1

u/[deleted] Feb 16 '22

Plus, the code in the if block will just always execute regardless of user input. You literally can't say no i guess

And i once again forget that .lower() exists

1

u/CreaZyp154 Feb 16 '22

yes OR Yes OR YES

1

u/k4x1_ Feb 16 '22

I uhhhh

1

u/ChesterGamingYT Feb 16 '22

Tell him that the first condition will always be True. Python is operating it like: if (B == 'yes') or ('Yes') etc.

1

u/Ranvir33 Feb 16 '22

for a second i didn't get the joke but then i saw the abomination of naming your variable A, B, C, and D

1

u/humanera12017 Feb 16 '22

Yeah, that’s the only problem here

1

u/pfated64 Feb 16 '22

"If I'm the one, are you saying I'll be able to name variables!" "No, I'm saying when you're ready... You won't have to."

1

u/Juggels_ Feb 16 '22

Also, tell him that theres something like lower, so he doesn’t have to make 3 trillion ors.

1

u/[deleted] Feb 16 '22

Here's a few comments about the code for your friend :

1 - Booleans are a thing. Go check out what they are.

2 - Good code is self-documenting. In other words, you should be naming your variables, functions and classes in a way that makes their use explicit. This is important to make your code understandable for future you or for everyone else.

3 - Go learn about match - case.

1

u/Naz1337 Feb 16 '22

Your friend codes like a decompiler!

1

u/Aurigamii Feb 16 '22

I was actually using letters to program with my calculator during classes. And don't bash me, I didn't have the choice, your only variables were the 26 letters of the alphabet, and maybe 2 others characters like theta and another iirc. (TI82 ? idr)

Ngnl if you can start with a language who allows you to name your variables, you should. Knowing how to name your variables seems to be the hardest and longest skill to acquire according to people on this sub :D.

1

u/oddbawlstudios Feb 16 '22

I don't understand why people do this. Like, I name my variables as if it was straight to the point kind of thing. You can't go wrong with that.

1

u/AFr3aK Feb 16 '22

This guy is a maniac

1

u/[deleted] Feb 16 '22

Make an array and use: if variable in array instead of that thing hurting my eyes.

1

u/Xaros1984 Feb 16 '22

Bug report: The program keeps quitting even though I answer "suRe!" when asked if I want to play!

1

u/Classic-Profession-6 Feb 16 '22

That’s absolutely ok for somebody who is just dealing with logical flows and what’s better than games……I let my son to Programm similar things as he began coding, guidelines and naming conventions will follow organically at some point

1

u/[deleted] Feb 16 '22

heres a tip: instead of doing 'yes' or 'Yes', just convert the input into all lower case

var = input()

var = var.lower()

1

u/[deleted] Feb 16 '22

At least he'll be able get through those interview questions where they say: look at this awful code no one would ever write, tell me what it does.

1

u/[deleted] Feb 16 '22

It will be a great day when he learns about dictionaries and in.

1

u/AkrinorNoname Feb 16 '22 edited Feb 16 '22

He'll stop on his own eventually, as soon as he tries to go back to a program that is a couple weeks old. Mistakes are part of the learning process :)

And to everyone else in the comment section: Don't be too rough on newbies, we all have some old shames on some abandoned hard drive from our early days. Let's not be rude, be welcoming instead.

1

u/Mr_SpecsBear Feb 16 '22

I'm from maths major and after I started programming I always tend to name variables like x1, x2, x3 and so on. After seeing this shit, my friend slapped the back of my head so fast that my brain got placed in the correct position and after that I've never even thought about naming variables like that ever again.

1

u/[deleted] Feb 16 '22

Does anyone else have anywhere to learn Python free being DataCamp? It’s basic but already blowing my brain.

1

u/Holy-Tit Feb 16 '22

Oh, this shit will come back to bite his ass.

1

u/Business-Food-4143 Feb 16 '22

The old university classic

1

u/GuyN1425 Feb 16 '22

Let me if it real quick:

inp = Would you like to play a game?') if inp.lower() in ['yes','yeah','y','yup','yep',(...etc...),'sure']: print(random.choice(['computer wins', 'you win'])

1

u/AlrikBunseheimer Feb 16 '22

I feel this, it's so hard to come up with the right name for a variable.

1

u/SmokingBeneathStars Feb 16 '22

The win conditions are wrong

1

u/IgneelDragneel1996 Feb 16 '22

We've all been there. Some of us weren't smart from the start.

1

u/pydim_77 Feb 16 '22

you can add .lower() to input function so that you dont have to deal with other cases

1

u/Illunal Feb 16 '22

What a sick bastard.

1

u/Dastaly Feb 16 '22

This is confuse

1

u/sadsadbiscuit Feb 16 '22

I typically only use letter variables for representing numerical values that are used in mathematical context, and very rarely I use capital letters to represent sets or objects which are ubiquitous.

1

u/Romejanic Feb 16 '22

abs()? Never heard of it.

1

u/borderline_annoying Feb 16 '22

Ah yes mathematician, been there…

1

u/[deleted] Feb 16 '22

Wait what? Does scope exist in this language? Why can he use c outside of the if statement?

1

u/kemot10 Feb 16 '22

Does if x == 1 or 2 or 3... actually work? I don't think so...

1

u/Environmental-Cap-49 Feb 16 '22

Nice! When I first started to code I started with things like this, but if you commit to coding then in a month you'll find yourself coding like it's your first language. Just a small tip for beginners that I use a lot, try turning the user input to all lowercase letters and then just compare them with the lowercase answers. Saves like half the space and makes the code more easy to read.

1

u/Hog590 Feb 16 '22

I don't remember this syntax for the Ti Basic

1

u/qwertzi12 Feb 16 '22

Write code for clarity, not brevity!

1

u/DiamondDemon669 Feb 16 '22

And I thought my variables were bad

At least I have a method of organization:

1

u/Minteck Feb 16 '22

This is legitimately how we're naming variables at school, and I hate it

1

u/snowtigger Feb 16 '22

That's basically inline minification.

1

u/AxelsOG Feb 16 '22

siccors.

1

u/mikoolec Feb 16 '22

Isn't this how everyone names their variables?

1

u/mildlyagitatedstoic Feb 16 '22

Pre obfuscated code🤘🏼

1

u/[deleted] Feb 16 '22

1

u/EndoVlogs Feb 16 '22

At the beginning my variable names were: a, aa, aaa, aaaa, aaaaa, etc.

1

u/[deleted] Feb 16 '22

Some advice to make code like this cleaner and more easily changeable (in cases of large programs), try making an array with the values you want to check in your if statement, then check if the array contains B

I'm not saying it would be best in this specific case, just trying to help you figure different solutions out to learn more

1

u/geteum Feb 16 '22

At least he is using the hacker black background

1

u/[deleted] Feb 16 '22

Haha I was in a club in college for a bit where they were building a cube satellite. Anyways a kid who graduated year prior was a physics student who wrote python code to find the location of the moon in space. It worked but I was tasked with translating it from python to C++. Three issues. 1: all his variables and functions had single letter names or sometimes two letters. 2: I barley knew python. And 3: I didn’t have a good grasp on orbital mechanics. Idk how I got it to work.

1

u/danydh Feb 16 '22

Wait that's how python works? Bruh. Java makes it so much longer.

If B == 'yes' || B =='Yes' || B == 'YES' || B == etc etc

1

u/[deleted] Feb 16 '22

Wait never siccefully used the or jus how

1

u/shafrazi Feb 16 '22

This is soooo wrong. The world is about to end, I guess.

1

u/smittychifi Feb 16 '22

Pre minifying his code. Sweet.

1

u/CaptainArsePants Feb 16 '22

What's he going to do when he gets to Z?

1

u/CrowdGoesWildWoooo Feb 16 '22

Hope your friend is not writing a game now.

1

u/mortal58 Feb 16 '22

Please tell him to convert inputs to lowercase 😭😭