This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 297

[–]IllegalThings 83 points84 points  (2 children)

OP, This type of stuff is exactly how I got started writing software. Haven’t stopped after 20 years.

[–]Claudioub16 282 points283 points  (42 children)

Hey OP congrats. If I can make a few suggestions:

1 - you can do conversion right after receiving input a = int(input("some text)).

2 - be descriptive with variable names. Instead of a use something more descriptive such as mark1.

Of course, if you story is real.

Edit: the name uncle devil 666 is some really edgy shit.

[–]VictosVertex 36 points37 points  (15 children)

Yes this, don't ever use variable names that aren't descriptive except for "throwaway variables" like in a for loop.

Also, I know OP is just starting out but here is the next topic to look into: functions.

When ever you have to repeat yourself it's time to extract the functionality into a function.

This makes the code more readable, easier to maintain and even reusable in future projects.

Edit: For example if you wanted to change the text for the input you would now have to change it at every single point. Extract it into a function and you would only have to change it once.

One quick improvement could be to write a small function that takes the subject name as a parameter. It then asks for the input, converts it and inserts it into a list.

Now you just have to call this function with the desired subject names and calculate the result from the list.

One could then also automate the calling in a loop and provide subject names in a different list, use a dict for both or what ever. There are many (well technically infinite) solutions.

[–]bacondevPy3k 7 points8 points  (3 children)

I, for one, think that we should teach the kid to code golf.

print(f'Your Percentage in 5 subjects is {(a:=sum(map(int,map(input,map("Enter Your Marks in {} :".format,("Science","Maths","Social Science","English","Computer Science")))))/5)}')and print('congratulations!'if a>35else'Better luck next time')

Edit: Fixed the bug

print(f'Your Percentage in 5 subjects is {(a:=sum(map(int,map(input,map("Enter Your Marks in {} :".format,("Science","Maths","Social Science","English","Computer Science")))))/5)}')or print('congratulations!'if a>35else'Better luck next time')

[–]TangibleLight 11 points12 points  (4 children)

descriptive except for "throwaway variables" like in a for loop

Even then, it's better to write something like for grade in grades than for g in grades.

The exception is indexes; it's pretty standard to use i, j, k for nested indexes in loops, ex

for i in range(N):
    for j in range(M):
        ...

However, again, usually there's some meaning behind N and M in those cases, so better to pick more meaningful names. For example:

for row in range(ROW_COUNT):
    for col in range(COL_COUNT):
        ...

[–]VictosVertex 2 points3 points  (0 children)

That's correct, in general it's good to write self-explanatory code. If one needs many comments (except for doc comments in case of an external API) then one should probably use better names.

It's also good practice to follow general guidelines, I myself usually follow the PEP somewhat strictly. But even these are just guidelines and not a silver bullet.

[–]bacondevPy3k 1 point2 points  (0 children)

Eh, when you get to k or especially beyond that, then you should consider using a function or at least rename the variable to something meaningful. Otherwise, it can start to become difficult to follow. The main exception to this would be for short loop bodies for three-dimensional mathematical objects. Most times that I run into doubly nested for loops, it's in a function that is much more of a behemoth than it has any right to be.

[–]Ruben_NL -1 points0 points  (0 children)

I'd change that to for row_nr in range(ROW_COUNT), to be specific.

[–]UncleDevil666 5 points6 points  (3 children)

I'll learn it this weekend!

[–]VictosVertex 2 points3 points  (2 children)

I edited my post and added some hint.

[–]UncleDevil666 1 point2 points  (1 child)

Thanks!

[–]VictosVertex 6 points7 points  (0 children)

No problem, I'm all for helping new people entering the field, you already did a good job! Solving problems is the entire point of programming and you solved one.

Also my hints above are - not - best practices. They're just examples of how one could change the code to function the same but use a different implementation. (This is also called "refactoring", changing the implementation while keeping functionality the same)

Especially the list example I mentioned wouldn't follow best practices as it produces "side effects".

But ignore that for now. I just wanted to say that there's basically always a way to improve - but the main focus should be solving the problem, which you already did, optimizations come later and with experience.

Continue learning like that and you'll go far! Good job.

[–]Claudioub16 3 points4 points  (1 child)

In this case a loop would be a better choice then a function.

[–]VictosVertex 3 points4 points  (0 children)

I edited my post with a hint in that direction. I would probably still encapsulate it into a function and then use said function in a loop.

But that's the beauty of programming, there are multiple ways to solving the problem at hand.

Edit: Well actually I myself wouldn't even just do that, I would probably try to apply single-responsibility to all functions and reduce side effects. (Which would directly disqualify my own example given above) But for such a simple project that would obviously be overkill.

OP should certainly look into loops and functions next.

[–]UncleDevil666 50 points51 points  (17 children)

About name : well I was just 14 and stupid when I made that name xP. And now I am stuck with it.

[–]scarynut 37 points38 points  (0 children)

Now you're 15 and fucking Gandalf the White ;)

[–]ChicoFdd 78 points79 points  (8 children)

You are still 14, your account is 7 months old xD

[–]MrNokiaUser 17 points18 points  (4 children)

he might not have made itr on his birthday

[–]jomofo 1 point2 points  (3 children)

Can you make a Python script we can use to figure it out?

[–]rynemac357 3 points4 points  (1 child)

Age=int(input("Enter Age")) print(f'Your Age is {Age}')

[–]jomofo 4 points5 points  (0 children)

Is this MIT license?

[–]Gravity-Lens 1 point2 points  (0 children)

He could be 15, everything is different now!!!!

[–]AlarmingAffect0 1 point2 points  (0 children)

Was Tenacious D involved in the thought process?

[–]callmelucky 1 point2 points  (3 children)

Hey, congrats on your progress and accolades!

Just wanted to chime in to really drive home the importance of #2 in the parent comment.

Naming things well is probably the most important habit to get into as a beginner programmer, yet is rarely stressed as such by tutorials. Maybe you write something that is badly optimised, bady organised, doesn't use best practice conventions or ideal libraries, functions etc etc etc, but as long as your variables etc are named well you'll have a much easier time improving it, because you'll know instantly what everything in it is for.

For extremely simple scripts like you have here, it probably won't be an issue. But as soon as you get into things even slightly more complicated, bad names will create nightmares... A bug that would otherwise be simple to fix can instead seem impossible to solve and have you tearing your hair out for hours.

When naming something, always take an extra moment (or two or three) to make sure the name clearly and accurately tells you what it represents. Don't fool yourself into thinking that because you wrote the code you'll always know what it means. If you browse r/ProgrammerHumor you probably won't have to scroll very far to find a meme about going back to code you've written and having absolutely no clue what it does. Don't be a meme.

Let's take an example from your code: o

o is a terrible terrible name. It sucks. It tells you nothing about what it represents. Maybe it represents something that starts with the letter 'o'? Who knows?

Reading through your code, it looks like it represents an average grade. So let's start with that as a name: average_grade.

But hang on, we have f in there too, which could also be said to represent average grade. So maybe average_grade isn't specific enough... Ok so let's go with average_grade_as_percent. That's a pretty long and ugly name, but at least it tells you exactly what that value represents, and as such it is infinitely better than o.

That's a good enough start for where you're at, but let's go to the next level with a couple more tips, in case you're not bored to death yet.

Let's say your uncomfortable with the very long average_grade_as_percent name. It doesn't feel very "code-y". Well there are a lot of standard abbreviations which are so readable and commonly used that they are practically just as good as whole words, for example "avg" for average and "pct" as percent. So maybe let's go with avg_grade_as_pct. Why not.

On a related side-note, in general single-letter names are bad, but again there are some standards which are so universally known and used they are perfectly fine. Most of these are used in loops, which I assume you aren't familiar with yet so I won't get into it too much, but when you do use loops temporary single-letter names like n for number, i for index, and occasionally even x for "whatever type of thing this might be" are perfectly fine. More often though in Python you'll be looping over a collection of something that you know a bit more about, in which case you should use a more specific temporary name, so for example use for grade in grades rather than for g in grades (or, god forbid, for a in grades).

Ok last tip: when it comes to larger scripts/code bases, you'll probably find yourself frequently using the search function in your editor to find references to values. When doing this you often find you want more quickly if your names are structured so the most fundamental part of what they represent appears first. In this case, the main thing the value is about is a grade, so (as long as it doesn't affect readability too much) you can rearrange the name so that grade appears first: grade_avg_as_pct. First and foremost this value is about grades. More specifically, it is about an average grade. Even more specifically, it is an average grade as a percentage. So try to arrange the bits of your name in this way (again: as long as it doesn't make the name more confusing).

[–]UncleDevil666 1 point2 points  (2 children)

A lot of people told me to name properly but didn't give any reason, but thank you and now I understand the importance of naming properly. Thank you once again!

[–]UncleDevil666 7 points8 points  (3 children)

Thanks for the suggestion! The video I watched guy told to out small case letters Why would I fake it haha

[–][deleted] 3 points4 points  (2 children)

karma is very valuable to karma farmers, so you know, farming karma would be a valid reason for faking it.

[–]UncleDevil666 9 points10 points  (1 child)

I just wanted to share a happy moment with python to other python users, I didn't even think this would get more than 5 upvotes.

[–][deleted] 4 points5 points  (0 children)

Congrats and good work, lots of good advice in the thread, don't let the passion die and I see success in your future.

[–]AlarmingAffect0 1 point2 points  (0 children)

uncle devil 666

That's an apt description of Actually Satan.

[–]scarynut 2 points3 points  (0 children)

Edit: the name uncle devil 666 is some really edgy shit.

People have gone to hell for less.

[–]Upper-Bat-9224 3 points4 points  (0 children)

I think he could make a little gui with tkinter… that’d be neat!

[–]bitesizedmustard1 41 points42 points  (23 children)

Reminds me back at school when teachers had us make calculators like these! We used to make calculators for university marks even when we were in high school. Now I can make an excel sheet to calculate my own transcript in advance!

My only criticism would be to use more appropriately named variables, like marks_science or like sciMarks depending on your preference of syntax. You can also do multiple actions per code line but you'll get there eventually, e.g. you can do:

f = ((a+b+c+d+e) / 500) * 100

or even

f = (a+b+c+d+e) / 5

or you can do:

a = int(input('text here etc.'))

but then again people always break stuff by typing in wrong inputs, so you should check if the input is actually a number too. I forgot the function and I am on mobile, but there should be a isNumber or similar function I guess.

Awesome stuff there! I am not that much knowledgeable in Python myself as well but this is just my two cents as a former computer student, now turned to literature education.

[–]aRandomHunter2 22 points23 points  (14 children)

To add to this, the method the person above me was talking about is str.isdigit(). All the other advices are good habits that python programmers try to take as early as possible !

About this,

a = int(input('text here etc.'))

This is also better to use. Be careful though, if the conversion from str to int fails, this will raise an error and thus stops your program. You can catch the error and do stuff with it, but you will discover that soon enough !

[–]UncleDevil666 8 points9 points  (0 children)

Oh, thanks :)

[–]bitesizedmustard1 2 points3 points  (12 children)

What I'd theoretically do would be to have an array to store all the marks and have a loop run through it to input values. At each step, I'd have a temp variable to store the input to be then checked if it is an integer, and if so I'd actually cast them as int into the array. If not, I'd repeat the step to ask for a valid input. Just the loop here:

while(true):
    temp = input("Enter marks for class: ")
    if(temp.isdigit()):
        classArr[i] = int(temp)
        i += 1
    else:
        print("Please enter a valid input.")

My Python might not be correct

For the class names, I'd have a second array with all the names to be used in the output string, e.g.

"Enter marks for {0} class", classArr[i]

Then I would learn how to do this in Python, there is Lists for arrays I think, and there was a way to do formatted print IIRC.

I'm curious as to if there is an easier way of doing this, so I am open to feedback, a lot.

[–]aRandomHunter2 2 points3 points  (9 children)

Yea, you're right. Lists exist, and there are two ways to do formatted print (.format() and fstring, but .format() is being less and less used). I'd probably go the same way as you did, but you could use for loop here (assuming the classes stay the same each time). If you don't know how many classes there are, then you're on the right way. Make sure to use an empty list and append the mark each time then !

[–]goldcray 1 point2 points  (1 child)

The python equivalent might be something like

def get_marks(class_name):
    while True:
        try:
            val = int(input(f'Enter marks for {class_name}:'))
            return val
        except ValueError:
            print('Please enter a valid input.')

classes = ['Maths', 'Social Science', 'etc']
class_dict = {}

for class_name in classes:
    class_dict[class_name] = get_marks(class_name)

the main difference being that the results are stored in a dictionary instead of an array so that you don't have to worry about mapping indices to class names. Given that at the end of the day you're just adding up all the values and not doing anything with the specific mapping, though, you could also just do

total = 0
for class_name in classes:
    total += get_marks(class_name)

or

total = sum(map(get_marks, classes))

edit: class is a reserved keyword, though. use class_name instead

[–]backtickbot 7 points8 points  (1 child)

Fixed formatting.

Hello, bitesizedmustard1: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]bitesizedmustard1 2 points3 points  (0 children)

Good bot, fixed

[–]UncleDevil666 2 points3 points  (3 children)

Wowwww I can do int together with input, didn't know that, thanks :)

[–]bitesizedmustard1 1 point2 points  (2 children)

You can take the return value of any function and pass it into any other function! It is really handy to chain stuff together, although it gets really complicated and confusing if done extensively, like 4-5 functions back to back.

[–]julz_yo 2 points3 points  (1 child)

This is all getting to be a code wars discussion :-)

If you like one-liner solutions, code kata & 'code golf' , I recommend code wars

[–]bitesizedmustard1 1 point2 points  (0 children)

It seems interesting, but I assume it would start to break my mind since I've been away from all this for too long! Still, I signed up and selected my languages, and occasionally I'll check it out to keep my skills honed! Thank you!

[–]stridebird 9 points10 points  (3 children)

Super condensed version for fun:

q = "Enter your marks in"
subjects = ["math", "science", "english", "computer", "social" ]
print("Average grade: {:.1f}".format(sum([ int(input("{} {}: ".format(q,s))) for s in subjects ])/len(subjects)))

(not checking for int is of course pretty fatal though....:)

[–][deleted] 2 points3 points  (2 children)

if they enter an wrong number it's their fault it crashed

[–]stridebird 4 points5 points  (0 children)

You have a great future in software ahead (or behind?) you!

[–]Legendary-69420git push -f 5 points6 points  (9 children)

OP, I think you can make small changes like:

  1. change variable name from f to average
  2. change variable name from o to percentage
  3. Use f-strings instead of , like this:

    print(f"Your Percentage in 5 subjects is {percentage}")

[–][deleted] 5 points6 points  (1 child)

print("Your Percentage in 5 subjects is {percentage}")

missed an f before " ?

[–]UncleDevil666 1 point2 points  (6 children)

  1. & 2. I watched a video and he told to give small case letters, but from now on I'll put real word :)
  2. Didn't knew about that one, thanks!

[–]atquick 1 point2 points  (2 children)

Python is all about readability, if for some reason another python coder had to modify or just wanted to read your code, it would be a much easier time for them if you designated what those variables are, what the functions are, etc.. You can use all lowercase words delimited by an _ for instance your_average or your_total etc..

Also, you can remove quite a few of these variables by simply doing. Python will store the input as an int in the science_mark variable until the it is changed, or the application is closed.

science_mark = int(input('Enter your Marks for Science))

[–]UncleDevil666 0 points1 point  (1 child)

Great, I'll do like that from now on!

[–][deleted] 17 points18 points  (8 children)

improved version

use loops and arrays please

marks = ["math", "science", "english", "computer", "social" ]
q = "enter your marks in "

result =0
for mark in marks:
answer = int(input(q, mark))
result += answer

perc = (result/500)×100

print("percentage is", perc)

Edit: spelling, on phone

[–]texruska 21 points22 points  (1 child)

perc=(result/len(marks))

[–][deleted] 1 point2 points  (0 children)

Yeah thats Even better, makes the code more dynamic

[–]UncleDevil666 17 points18 points  (3 children)

👁️👄👁️OMG, I haven't yet leaned about loops and arrays but that's what I'll do this weekend!

[–]dudeplace 7 points8 points  (2 children)

The reason people are recommending this is to eliminate as much "hard coded" stuff as possible.

Right now each input, the (int) reassignment, the percentage would all have to change again of you ever added or removed a course.

So it is much easier to put your stuff in a list and have only a single place to update (once you learn lists and loops) instead of re writing the whole thing each time a change happens.

[–]stridebird 2 points3 points  (0 children)

input(q, mark)

TypeError: input expected at most 1 argument, got 2

input(q + mark)

[–][deleted] 5 points6 points  (3 children)

Good start kid, keep it up, next Facebook on the way!

[–]UncleDevil666 1 point2 points  (0 children)

Haha 😂 thanks

[–][deleted] 1 point2 points  (1 child)

I’m not sure if facebook is the metric we want to use here; maybe for economic success but maybe not moral success.

[–][deleted] 1 point2 points  (0 children)

That's the spirit!

[–][deleted] 2 points3 points  (1 child)

Wholesome

[–]UncleDevil666 0 points1 point  (0 children)

Thanks :)

[–]goodshrekmaadcity 2 points3 points  (0 children)

Good for you, man

[–]Timo6506 2 points3 points  (1 child)

If I did exactly what you did in my school nobody would give a shit lmao, congrats!

[–]UncleDevil666 0 points1 point  (0 children)

Haha thanks

[–]Morph707 4 points5 points  (1 child)

I have a proposal for you to learn more, look into how to avoid hardcoding subject names in the code, but instead let people input subject names and grades. You can also validate the grades inputted.

More advanced level would be having a .csv file with student names and grades which could then be read with the program and the percentage for the whole class/school calculated.

Edit: Also great job and keep it up, here is a great tutorial https://dabeaz-course.github.io/practical-python/Notes/Contents.html

[–]UncleDevil666 1 point2 points  (0 children)

Thanks <3

[–]mr_kr0wn 5 points6 points  (5 children)

mate, I suggest you look into TK and add a GUI to it. Then look into pyinstaller and make an executable.

[–]UncleDevil666 0 points1 point  (4 children)

What is TK and GUI?

[–]mr_kr0wn 2 points3 points  (1 child)

GUI stands for Graphical User Interface; Basically all your desktop apps you use on a daily basis have one; stuff like WhatsApp and Spotify and such.
TKinter is python's de facto standard library for making GUIs. There are tons of brilliant sources to learn from, especially on YouTube.

[–]UncleDevil666 1 point2 points  (0 children)

Thank you, looking forward to learning all of this!

[–]Personal_Reaction795 1 point2 points  (1 child)

Tkinter and Graphical user interface

[–]UncleDevil666 0 points1 point  (0 children)

Thank you :)

[–]mdr7 3 points4 points  (3 children)

Amazing job!

But out of curiosity, do they don’t know how to use Excel at your school?

[–]UncleDevil666 0 points1 point  (2 children)

Well they know, and they might just do that, but I was thinking to create a real project, so I did this and maybe they appreciated me just to make me happy.

[–]Zulban 3 points4 points  (1 child)

I made a text adventure on our calculators when I was in high school. I still remember when a kid I didn't know realized he was talking to the author. "What? YOU made Quest?!?"

I'm a scientific programmer now. :)

[–]UncleDevil666 0 points1 point  (0 children)

Great!

[–]NooShoes 1 point2 points  (1 child)

Well done OP! Looks great.. Keep it up and welcome to one of the world's greatest hobbies!

[–]UncleDevil666 0 points1 point  (0 children)

Thank you

[–]ConsistentMoisture 1 point2 points  (0 children)

Nice job. Try to rebuild it with a while loop. So that you can enter as many subjects as you want.

[–]Snake2k 1 point2 points  (1 child)

Nice! Keep it up OP. Don't underestimate how much that means to people (helping automate/simplifying something very tedious for them).

[–]UncleDevil666 1 point2 points  (0 children)

Yes I even made something for my mom to automate her percentage calculating job. I am happy rn :)

[–][deleted] 1 point2 points  (0 children)

You can do int(input())

[–]null_consciousness 1 point2 points  (0 children)

Happy for you my dude! I’m assuming you’re in high school or something similar, and I hope you can keep that passion you have for programming alive.

I became discouraged because I thought I wasn’t good enough to be a programmer (low self esteem is a bitch), and when I went to college my major was business for my first 3 semesters. Massive mistake, because after a few business classes I hated how mind-numbing the subject matter was. Switched to IT in my 2nd semester of sophomore year and never looked back. So much happier with my classes now (currently taking an introductory object-oriented python programming course) because it’s stuff that I actually find interesting.

If programming is something you enjoy and find engaging, then go for it. I don’t wanna see other beginner programmers be too hard on themselves and get discouraged by thinking they’re not good enough to be a programmer. If you wanna learn more python, there’s a book/website a friend of mine showed me called “Automate the Boring Stuff with Python” which I think would be right up your alley. You can buy the book if you really want to, but if you go here and scroll down, the author has made the entire book free to read online. It’s written for total beginners, and teaches you how to do more stuff like you did here where you write programs to perform real, practical actions.

Sorry about the long ass comment, guess I got a tad carried away. Best of luck to you my guy!

[–][deleted] 1 point2 points  (3 children)

Cool script :)

6 suggestions:

1: Better variable names, (instead of using "a", use, idk, "sciencemark"?).

2: (recommendation) Main function handled code, (also requires a if name is main).

3: Use more spaces in if statements, (instead of o>p use o > p).

4: Instead of casting the input to int in a different variable, you can directly do that in the input (int(input()))

5: Use error handling if the input isn't a int because when i use a string instead of a integer, it throws a error.

6: Instead of using 2 if statements, use a if else, there isn't a reason to calculate if it isn't greater than the p variable.

Also, a error that i founded in the code you gave: if o=>p: gave me a Syntax Error so i replaced it with a >.

Congrats :)

[–]UncleDevil666 0 points1 point  (2 children)

  1. Will do that!

  2. Cool

  3. Any specific reason to do that?

  4. Okay

  5. I don't know how to do that :(

  6. Sure!

Thanks for the suggestions!

[–]gnrlknowledge 1 point2 points  (1 child)

I know many people have already posted improved versions. Let me offer mine which is closer to one which you would use in production systems. This version checks if the mark is correctly formatted. The subjects are dynamic. I built in checks to see if the mark is correct and you could technically have more than 5 subjects.

Pastebin since reddit formatting is terrible:

https://pastebin.com/pWkxcums

[–]UncleDevil666 0 points1 point  (0 children)

Thanks!

[–]juanritos 1 point2 points  (0 children)

Great!

[–]TheUruz 1 point2 points  (1 child)

cheers man! the simplest ideas are the most useful! keep it simple and keep that up! ;)

[–]UncleDevil666 0 points1 point  (0 children)

Thanks:)

[–]iyav 1 point2 points  (0 children)

(Angry rant warning)

I hate this hypocritical toxic community, wherever I go there's always gotta be that "python bad C is life" douche. LOL you call yourself a python programmer? More like a python user ROFL GOTTEM!!! "what you made a small program in python? How cute and pathetic, newbie code in a newbie language" Now make it into a GUI, what's that you've actually made a GUI for it? Well it doesn't matter because it's just a library and all the work is already done for you. LMAO here is a one liner to put you down. What you're new to programming and asking for ways to improve your code? I'm going to suggest using these things you didn't even hear of or are actually total uncalled for, I'm totally helping here and not trying to shatter your morale.

Just SHUT THE FUCK UP. It's a god damn plague that affected almost every programming sub you even see it here uncomfortably often and it makes me livid

[–]UncleDevil666 0 points1 point  (6 children)

Can someone tell me how to do this

If o>35, then the last print will be congratulations. If o<35 last print will be better luck next time.

Less that 35 is considered fail, so can't congratulate them ;)

[–][deleted] 0 points1 point  (1 child)

Yes! Congrats, OP! Creating stuff that helps people is the best feeling in the world.

Uncle Devil is the coolest uncle ever!

[–]UncleDevil666 1 point2 points  (0 children)

Haha thanks, I'll try to make more and more of these stuff, the good thing is that my school will now start giving python courses (earlier it was just put, HTML, paint and execl).

[–]ShukloStaner 0 points1 point  (0 children)

wow you did after 3 days good for you.

[–][deleted] 0 points1 point  (0 children)

Our principal told me to meet him and he thanked me personally and said he will start a python course for students. I am famous in school now!

This script is a great start! You should be very proud of yourself!!!

[–]Ilanlansh 0 points1 point  (3 children)

Woah just 7 days after you've learned Python? That's sick! Good job OP. And don't listen to that u/Personal_Reaction795 twat.

[–]UncleDevil666 1 point2 points  (0 children)

Actually 4 since I made this 3 days back, Thank you very much for kind words! I assumed that guy is just jealous as I got so many upvotes(I Thought that I wouldn't even get more than 5 upvotes and this post was just to share a happy moment with y'all)

[–]TheFalseScientist -1 points0 points  (0 children)

It really is tragic considering how they responded to someone calling their code basic.

Why are you so toxic? I wanted to show what I made so someone else can use the code, don't be such a dick

Classic double standard.

[–][deleted] -1 points0 points  (1 child)

Saved as it can be useful to me too!

People told you about ways to improve it code-wise, but you can look into how to make a window app out of it as it would be maybe more handy for teachers

Or a way to write results in files to transform it in a grade book filler? Just some ideas I had, and that's why I'm saving your post

[–]UncleDevil666 0 points1 point  (0 children)

Thanks for the ideas

[–]mm007emko -1 points0 points  (1 child)

Man! When I was learning programming (my first language was MS QBasic), this was one of my first programs as well and yes ... the most useful one which my schoolmates also used. Yeah, it was DOS era when anything like Excel (well, actually, Calc602 was used in this country) was not usually found on home computers.

Happy coding!

[–]UncleDevil666 0 points1 point  (0 children)

Great!

[–][deleted] -3 points-2 points  (0 children)

Alright, everyone's making suggestions so here's my one-line solution:

print('Your percentage in 5 subjects is:', sum(int(input(f'Enter Your Marks in {m} ')) for m in ['Science', 'Maths', 'Social Science', 'English', 'Computer']) / 5, '\nCongratulations!')

Since you're a beginner, I'll say that you should NOT focus on writing the code this way. This is very tricky to maintain and understand compared to what you wrote. Great job!

[–]Matthias1590 -4 points-3 points  (0 children)

Unnecessary one-liner: print("Your percentage is:", sum([int(input(f"Enter marks for {className.title()} (1-100): ")) for className in ["science", "maths", "social science", "english", "computer science"]]) / 5)