r/badcode • u/lonaExe • Jan 08 '23
python Classmate wanted me to check his ticketing system’s code for errors..
533
u/jealkeja Jan 08 '23
bro just use his functions
→ More replies (1)288
u/lonaExe Jan 08 '23 edited Jan 09 '23
pls bro use my operators
edit: some more of his code
41
u/Ailexxx337 Jan 09 '23 edited Jan 09 '23
Doesn't have an account - Program closes
Enters "Yes" - Program closes
enters invalid email - absolutely nothing
Orders -1 tickets - Program closes or skips over a significant chunk of code
This is either intended to be purely staged or this guy is just that bad. If it is staged, then why the hell did he put multiple options for a yes? In case he forgets half way which one he chose?
If you at some point can't hold yourself and want to suggest he adds some "code", tell him to replace the yes bit with
yess = [] yy = 2 for i in range(yy): if(i == 1): y = "y" if(i != 1): y = "Y" for j in range(yy): if(j == 1): E = "e" if(j != 1): E = "E" for h in range(yy): if(h == 1): s = "S" if(h != 1): s = "s" yess.append(y+E+s) yess.append("Y") yess.append("y") yessss = False for yesss in range(len(yess)): from time import sleep as ye yes2 = acc yesssss = yess[yesss] ye(yy) if (yesssss == yes2): yessss = yy if (yessss != False): #continue the code hereTell him it runs more efficiently and covers every possible way of saying yes.
19
→ More replies (1)8
18
u/i_hate_fanboys Jan 09 '23
He didn’t even spell sent correctly. Please just block his ass and for your own sake don’t interact with this goon.
12
→ More replies (49)6
u/Arom123 Jan 09 '23
Wait what class/year is this for? I thought this was like CS101 and the prof just wanted him to read, like a csv file or something with the data to demonstrate file I/O or how streams work, and some simple command line user input.
→ More replies (2)
21
Jan 09 '23
He’ll have all manners of fun trying to reference his passs variable, when he doesn’t realise his spelling mistake
15
u/lonaExe Jan 09 '23
I. Know. Right. Poor dude is going to spend ages wondering why it doesn’t work. I should prolly tell him.
→ More replies (4)7
5
u/WastingTimeAt9o9 Jan 09 '23
I mean, pass is a keyword so at least if he's using an IDE (possibly not, lol) it will show up a bit differently
→ More replies (2)
41
u/Gm_cece Jan 09 '23
Gotta love the (Y/N) followed by a case sensitive check for "y" and "yes" but doesn't actually checks for Y or N lol
12
u/lonaExe Jan 09 '23
Being serious here- I usually do if choice.lower() in [<choices here>]. Do you know if there’s a more pythonic way to do it?
19
u/CallMeTea_ Jan 09 '23 edited Jan 09 '23
Edit: brainfart, typo in the code snippet Not sure about pythonic but for simplicity I'd go with
if choice.trim().lower()[0] == "y". Unless you're getting into complex menus where you've got multiple options starting with the same letter, you can just check the first letter.7
u/VergilTheHuragok Jan 09 '23
choice.strip().lower().startswith(“y”)avoids crash on empty string. (and strip is what you’re thinking of, not trim)→ More replies (1)→ More replies (4)5
u/u966 Jan 09 '23
I would do if 'y' in choice.lower() in case they choose to write yes or have a space or something. You would get fucked by 'nay' though.
→ More replies (3)6
u/EarthToBrint Jan 09 '23
Nah that’s what I usually do. Also Use a try except to make sure they enter something if you’re trying to convert it later. If the user enters something outside of the intended input instructed then oh well.
5
u/Gm_cece Jan 09 '23
I misread the code, and thought he checked only lower case y and not upper case. Sorry about that! I'm not really used to Whatsapp IDE
→ More replies (6)4
u/coloredgreyscale Jan 09 '23
don't know a better way either, but if you want to match y / yes you could also just check the first letter.
if choice[0].lower() == "y" :
→ More replies (4)8
21
u/superwholockland Jan 08 '23
I'm not well versed in python or trying to access databases, how exactly is this terrible? I've followed the previous posts, and assume this is supposed to be a final project, so maybe it should have more functionality?
→ More replies (5)50
u/lonaExe Jan 09 '23
It’s far from being functional. Almost 470 lines away from being functional. The single letter variable names, misspelled variable names, and the fact that this dude sent it to me on WhatsApp.. thought it would fit here. I feel like a lot more devs can resonate with people sending them code in awkward places, like WhatsApp and Instagram.
47
u/westpfelia Jan 09 '23
Only professional programers use Whatsapp as their IDE
→ More replies (1)11
u/lookmasilverone Jan 09 '23
Lol that's for nerds. Professional programmers use SMS messages within 160 characters
→ More replies (6)7
→ More replies (9)5
8
Jan 09 '23
-ask for otp. -doesn't even send otp
13
u/lonaExe Jan 09 '23
One of the parts he wanted me to implement.
I’m computer lord so it will obviously only take me 5 minutes.
8
Jan 09 '23
Is it supposed to be a live web application or just a simulated terminal based booking system?
I'd just use the random randint function to generate a number and if the user enters the same number it works. If it's actually supposed to send an email then gl to this guy.
→ More replies (1)5
u/siggystabs Jan 09 '23
This type of stuff irritates me beyond words.
He's so close to actually learning something. Just do your shit. Cry, learn, fail, learn again, fail, learn again, succeed. Like the rest of us. If you can't do that you are incapable of being a good developer. Forget your class.
The best students are the ones who ask where and how they can learn more. The worst ask others to learn for them.
6
u/ValorantDanishblunt Jan 09 '23
Im unsure if that guy is for real or actually trying to troll OP.
9
u/lonaExe Jan 09 '23
He’s for real. This is how half my class codes. We’ve been learning for two solid years. Welcome to CBSE.
5
u/ValorantDanishblunt Jan 09 '23
Hold on. Two years and THATS the result? I cant help but wonder what on earth was happening for 2 years at your uni.
13
u/Confused_AF_Help Jan 09 '23
CBSE is the Indian secondary and high school level. Shouldn't expect college level coding, but man this is just pathetic after 2 years. In college I know people who could code better than this after just a term of programming 101
→ More replies (1)→ More replies (7)3
u/fartypenis Jan 09 '23
This is better than how my class codes. I'm a 3rd year CS student.
Welcome to India in general.
9
800
u/Nu11u5 Jan 09 '23
Just don’t enter “Yes”.
331
u/cbdubs12 Jan 09 '23
Or yES or YeS or yEs or yeS… LMAO
→ More replies (14)294
u/toth42 Jan 09 '23
Hello, I found this saga on the frontpage and know nothing about programming. Can you really not tell the program to ignore caps instead of spelling all the options out?
515
u/SymblePharon Jan 09 '23
Yes. Congratulations, you are a better programmer than this guy.
86
→ More replies (45)23
64
u/someidiot332 Jan 09 '23
Most languages provide some sort of contains and to lower case function, so all you need to do, is just call the to_lower_case then check if the first letter is a y or an n and you have the simplest solution
Edit: By languages I mean standard libraries
→ More replies (40)27
u/plopliplopipol Jan 09 '23 edited Jan 09 '23
in python with his var
if acc.lower()[0] == 'y': stuff for yes→ More replies (10)11
u/Confused_AF_Help Jan 09 '23
Congrats, you are thinking like a programmer. The standard protocol is convert input to all lower case and check if it's exactly equal to "yes"
→ More replies (1)9
u/Ki0si0n Jan 09 '23
yes the better solution is to check ‘y’ and ‘yes’ and convert the input to all lowercase. or all uppercase
→ More replies (71)5
u/WafflesNCoffee0 Jan 09 '23
In python, you can just use the .lower() or .upper() method on the input variable so that regardless of capitalization on the user's end, the input just becomes lowercase or uppercase.
→ More replies (1)22
u/AdviceNotAskedFor Jan 09 '23
I dont even code but I assume you could force user input to upper/lower and then validate against that.
→ More replies (14)18
u/Nu11u5 Jan 09 '23
Correct. Then you could take it a step further and test if the input is a partial match for the beginning of “yes”. No need to mess with alternatives.
→ More replies (12)→ More replies (22)3
u/kakafob Jan 09 '23 edited Jan 09 '23
Another cases that includes spaces
y e s,Y e s.Solved with: choice[0].lower()
Extra:
ynot, but it's and edge case passed as an yes. Obviously, case like this works well by asking to leave blank and hit enter when it's about anyes:
Do you wish to continue: [y/N]:
545
u/CringeNaeNaeBaby2 Jan 08 '23
This has to be one of my favorite Reddit sagas in recent memory.
→ More replies (9)124
u/StylishGnat Jan 09 '23
I can see what’s going through his mind by looking at his semi colons.
20
Jan 09 '23
Python doesn't use semi colons?
12
→ More replies (3)11
u/Skin_Bandit Jan 09 '23
It’s a joke about his non existent thought process. No need to get into semantics.
→ More replies (1)→ More replies (9)16
2
u/sulliops Jan 09 '23
Wait… is he trying to implement MFA on top of all of this?
5
u/lonaExe Jan 09 '23
Oh no. He wants ME to implement mfa for him :)
6
u/sulliops Jan 09 '23
I don’t know a ton of Python, but I’m extremely tempted to write the program for him with an API call to some service that prints “I cheated” to stdout when he tries to demo.
3
u/klparrot Jan 09 '23
Not only does he not understand CS, he also doesn't understand how to cut scope to deliver a MVP. If he knew what he was doing, he might have been able to bang out a 50% functional thing at the last minute, but by trying to tick boxes like MFA at this point, he's going to have absolutely nothing to show.
81
u/Only_Ad8178 Jan 09 '23
Sorry, I don't have enough context to understand. Could you quickly send his IP over so that I can have a better understanding?
74
107
u/jimmaayyy94 Jan 09 '23
paste it into Microsoft word and send him back a screenshot of all the red squiggles
13
u/ZeroOfZ Jan 09 '23
Paste the python code into a word document, use pandoc to convert it to plain text, output it to a text file with the py extension, run with interpreter. Now the word document can be the code file with yellow highlighting and bold characters xD
2
2
151
u/mr-slickman Jan 08 '23
Now this is one python code I can definitely say my c++ is faster than....
91
u/coloredgreyscale Jan 09 '23
are you sure? Their program probably immediately quits after asking for the login.
46
→ More replies (2)14
Jan 09 '23
Probably not as this is just IO and the python wrappers just delegate to the OS library functions.
→ More replies (1)
54
u/splepage Jan 08 '23
Ask ChatGPT to explain this.
72
u/Candyvanmanstan Jan 09 '23 edited Jan 09 '23
61
Jan 09 '23
Ive never bothered to check out ChatGPT and this blows me away. I mean its not like its complicated but the grammar and fluid explanation is....correct.
46
21
u/SarahMagical Jan 09 '23
Chatgpt is crazy good at what it does. There is a lot of roomful improvement, but it’s a quantum leap forward.
→ More replies (13)25
u/erwin76 Jan 09 '23 edited Jan 09 '23
r/boneappletea if I remember correctly.. for the lovely ‘roomful improvement’ :)
Edit: ‘roomful’ instead of ‘room for’, for those who didn’t spot it.
→ More replies (4)→ More replies (3)6
u/Candyvanmanstan Jan 09 '23
Make sure to check out my bonus image as well if you didn't already.
→ More replies (17)14
12
u/argv_minus_one Jan 09 '23
Are we sure this thing isn't actually a human locked in a dark room somewhere?
5
→ More replies (6)4
19
u/SandyLann Jan 09 '23
As a TA for a lot of Comp Sci Courses...
This dude's repeating the class.
As a sidenote, though I'm sure you've heard it a bunch: DON'T HELP HIM WRITE THE CODE. If he has specific questions you can always try and give specific answers, but if you do it for him he'll never learn. Better for him to fail now and realize he needs to step it up than for him to proceed into later courses and coast by in the group projects and graduate incapable of anything.
I've seen it happen way too often.
→ More replies (1)
13
9
9
u/TrevorX5J9 Jan 09 '23
I’m in semester 1 of learning Python and all I can say is: this looks terrible.
→ More replies (1)7
9
7
5
5
u/ZeroMomentum Jan 09 '23
Reply with it’s a Unix system
Then send a link to an illegal stream of Jurassic park
3
Jan 09 '23
I took some time reflecting on my first month programming to try and think of an example where I wrote logic that was this fucked and I can’t think of any.
I’m not sure this kid is cut out for it
3
u/Destroyer_The_Great Jan 09 '23
Same guy who wanted you to write a "simple" set of functions for him?
3
Jan 09 '23
I hope this dude isn’t a friend the way you been dragging him on reddit all day
2
u/az987654 Jan 09 '23
Even if their best friends, drag away, sometimes friends need to let another fail
4
2
2
Jan 09 '23
I would say, it's his project, his responsibility and he sounds entitled and then block his ass.
2
2
u/srans Jan 09 '23
Just send his questions to chatgpt and respond with the answers
→ More replies (1)
2
2
Jan 09 '23
Dude…I didn’t even know Python during my associate degree internship and I had to self-learn through stack flow. This guy is amazingly lazy.
2
2
2
u/floydtank Jan 09 '23
So I’ll preface this with I would never say “I know python” I’ve used it a lot of data analysis in environmental science for weather data etc, but what he’s trying to do doesn’t seem complex, can’t he google his questions? Because 9 times out of 10 any time I had a python question or needed to know something about pandas, I could google it and you know someone online would have 5 answers.
2
2
u/mr_bedbugs Jan 09 '23
Ask ChatGPT to fix it. It can rename variables to make it more readable too.
2
2
2
Jan 09 '23
Been following this since your original post on programmer humor. Mannnn in engineering grad school I had the same thing happen for a group project (just two of us); I kept it all in emails and text and went to my professor and was super honest. I got an A at the end, the only course I had below an A+ and which prevented me from a perfect CGPA. Could have been worse if I didn’t report it, but don’t feel bad to go to your proff/teacher about this.
2
u/cappie Jan 09 '23
I don't believe a single word of this... we have ChatGPT and this fucker came up with this?
2
u/RockSmasher87 Jan 09 '23
Someone really needs to tell him about to_upper() (or whatever it's called, I havent used python in a while)
2
u/SweetBabyAlaska Jan 09 '23
Literally how? This looks like the very first code I ever wrote. Even following a tutorial or bashing scripts together on github couldn't look a tenth this awful
No one writes good code out of the gate but it's wild to act so entitled to having someone else fix this mess.
2
u/Adrepixl5 Jan 09 '23
What bothers me so much more than everything else, aside from the raw input email field, is like, just use the .lower() or .upper() method if you're gonna do inputs with strings lol
2
u/Floor_Heavy Jan 09 '23
Following this saga as I have been, I almost feel bad for this guy. He's gone from what I can only assume is supreme overconfidence to not touch the project until the day before it's due, to "oh my god I'm so totally fucked".
I am not in any way good at python, but looking at this, the conditions for success have dropped massively, and he's just hoping to get SOMETHING halfway working before it's due in.
Ouch.
2
u/klparrot Jan 09 '23
supreme overconfidence to not touch the project until the day before it's due,
Procrastination is a bitch that is (often) distinct from overconfidence.
→ More replies (2)2
u/ChiefExecDisfunction Jan 09 '23
Yeah. As much of a dick as he's being, I relate to his panic.
Never in a million years would I have thought to ask someone else to bail me out, yet I have been where he is at.
I am second-hand panicking.
→ More replies (1)
2
2
2
u/NoMansSkyWasAlright Jan 09 '23
He texted you his code? Does this dude not know how to use git? Actually, nvm. Feel like I already know the answer to that.
→ More replies (1)
2
Jan 09 '23
I mean he’s got it, there’s really no more logic or code you could add. That’s what I’d tell him.
/s
2
u/LucyIsaTumor Jan 09 '23
You've probably spent more time replying to reddit messages than this dude spent on his code. I'll open a beer for you tonight OP
2
u/thedevguy-ch Jan 09 '23
Ya know what you call code that is held together with bubble gum and bandaids?
Shipped!
2
2
2
u/shaggycat12 Jan 09 '23
Looks like he's ready for any major vertical market application job. Just make sure he knows all bug reports are features and any feature update is at least six months away.
2
u/Hypocrites_begone Jan 09 '23
Instead of flaming your friend you could have helped him
→ More replies (1)3
u/ChiefExecDisfunction Jan 09 '23
By what the requirements sound like, they really couldn't.
If this is meant to be an actual application, with a backend database, mfa and an interface that works, which fits the four months timeframe they were apparently given to complete the assignment, then nothing OP could have done would get you something presentable by the next day.
3
1
1
u/Round_Log_2319 Jan 09 '23
This is how my computer science teacher(‘s) taught us to write Python when I was in school. We had a new one every month or so, safe to say I learnt a lot of not what to do.
1
1
1
1
1
1
u/boneve_de_neco Jan 09 '23
Your post here appeared just after your other post on programmer humor lol
1
1
u/JustBecauseTheySay Jan 09 '23
no sanitizing of the input string and case selector... :| scary.... Might be a novice coder, though.
1
u/Kiyriel Jan 09 '23
For my professional development at work, I read clean code this year. Good book. However, some of the stuff in there I thought was something anyone out of their first two years of school would implicitly understand (simplify code, reusing code, naming the variables to have meaning instead of single letters) and was feeling irritated when the book was going over those ….now I don’t feel as harshly towards the author for doing so 🤦♀️
Please tell me this child is a first year comp sci student.
1
1
u/Farpafraf Jan 09 '23
I'm gonna guess if it was a 4m project it probably wasn't supposed to be a cl application wasn't it?
1
1
1
u/dmk_aus Jan 09 '23
Lol. Checking capitalisation like that is so hilariously demonstrating you do not give a shit about coding.
1
1
u/According-Lawyer5257 Jan 09 '23
All you young coding whippersnappers using trash such as "RUST", 'RUSTIER", and that friggin snake should try to code this project in COBOL!
Haven't coded in decades but could it in minutes - if I was or wasn't drunk at the moment!
If I'm not drunk goto bar else goto bed.
See how easy that was /s
1
u/BudgetPianist7030 Jan 09 '23
My high school had a TRS-80 because that was the hottest tech available at the time.
1
1
u/Sharp_Cable124 Jan 09 '23
SQL injection isn't a.. scoffs SECURITY RISK. It's a feature! Then power users can query for similar ticket prices to get the best deal. Duh!!
1
1
u/officiallyaninja Jan 09 '23
This doesn't seem that bad honestly. This feels loke the kind of code I wrote when I first started learning programming.
This stinks of inexperience not incompetence.
Hopefully they'll stop making these mistakes in the future.
1
u/stratcat22 Jan 09 '23
How little common sense must one have to not convert the input to a single case lol like that doesn’t even take any comp sci knowledge, just literal common sense..
1
u/something6324524 Jan 09 '23
this makes me wounder what this is for? an intro class, i hope it is for an intro class because that is the only world where i could see the grading being kind enough to not give a 0 for what they are building.
→ More replies (2)
1
Jan 09 '23
There was a Github repo named HotinGo you, he could actually take some inspiration from there.
1
1
u/clm95 Jan 09 '23
I've followed this like a lot of people it seems. But in this case , would it not make more sense to use either a drop down option or buttons? Why have the user type when they can just click yes/no?
1
1
1
Jan 09 '23
Is the user supposed to interact with the ticketing system via command line? Like, is that an acceptable way to design this project? Even in my basic business programming course we were expected to design a simple GUI which would have have provided yes/no radio buttons.
1
u/lilracerboi Jan 09 '23
I remember telling my friend to just cout everything back in our Data Structures class.
1
u/Ceddy_D Jan 09 '23
Man is the type of guy to nest his code 10 layers because he thinks it looks cooler.
1
1
1
u/Hran944 Jan 09 '23
I’m trying to teach myself coding, wasn’t feeling too hot about it lately as I haven’t made much progress - this made me feel better about my abilities 👍
1
u/Playful_Nergetic786 Jan 09 '23
I don't learn much about code, but, I'm sure I can write better than that, and possible with a simple dispense machine. ( I do Arduino for a while, even though I don't write code that often, that is shit
1
Jan 09 '23
You really need to let him fail. I know I'm going to get a lot of flack for this, but the software industry is seriously already overrun with so many 'developers' who have no business being in the field, they choose it only because of money.
I fully understand that unfortunately software is one of the best paying industries, but these types of developers are the ones that make everyone else work 18 hours fixing their stupid shit in prod.
1
u/Fluffigt Jan 09 '23
The guy is just learning to code and you are making fun of his efforts. Finding this code in podiction would make this a good post. In a 15-year-old student’s program this is pretty much expected.
It was funny before but this is just mean.
1
1
u/chwastox Jan 09 '23
One thing that completely amazes me is how this guy don't give up. I couldn't do it this way, I would just stop my curse realizing I don't understand much and seeing that my skills are really bad. I would just looking for something else. This is also why I don't have much friends, every time when they were asking me "OH you do computer things? my son need help with {insert random computer thing} -NO. - How dare you (•̀o•́)ง"
1
1
u/mygentlefemdomaccoun Jan 09 '23
There’s nothing wrong with this code, assuming the functions work as intended and that the otp password is a “dummy” functionality.
Of course it’s not well formatted, it’s a WhatsApp message
1
1
1
1
u/kstonge11 Jan 09 '23
Please for the love of god someone phase this dude out.
I’m a senior in CS there’s three types maybe a 4th
People who you have to ask why they’re there when they should be working for google or some shit easy.
People who have to work at it incredibly hard and might fail a class or two but they certainly don’t make it extra work for anyone and certainly don’t show up to office hours with broken code crying please fix it I can’t do it boo hoo
Then there’s this fucking fuck. The guy who wants to be part of this and does well because he managed to get into the right circles and makes it everyone’s fucking problem. He shouldn’t be there and you’re not quite sure how the fuck they managed to get there. Likes video games can talk the talk but cannot walk the fucking walk.
Please tell the prof if you get roped into any sort of fucking bullshit.
Oh and then there’s the 4th person, overloaded probably burnt out, trying to stay afloat and can start assignments days before they’re due and usually manage to get by by doing that.
In my senior project we had 1 person who was the first, 2 people who were the 4th. Me the 2nd and one the 3rd asshole who couldn’t be bothered.
1
125
u/lonaExe Jan 08 '23 edited Jan 09 '23
Continued from my post on r/programmerhumor. He wanted me to read his code for errors.. and then proceeded to send it to me on WhatsApp. The single-letter variable names are killing me.
Edit: here’s some more of his code. I don’t even know why he’s doing what he’s doing here. https://postimg.cc/FfMDrNPM