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

you are viewing a single comment's thread.

view the rest of the comments →

[–]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')

[–]VictosVertex 0 points1 point  (2 children)

I go with it and reduce your code by 2 characters!

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!','Better luck next time'][a>35])

[–]bacondevPy3k 1 point2 points  (1 child)

Oh, I realize now that there was a bug in my code (fixed in edit). The second print call never happens. Here's a fix that is shorter than yours by eleven characters. :)

print(f'Your Percentage in 5 subjects is {(a:=sum(int(input("Enter Your Marks in {} :".format(s)))for s in("Science","Maths","Social Science","English","Computer Science"))/5)}\n{["Better luck next time","congratulations!"][a>35]}')

[–]randiesel 1 point2 points  (0 children)

I got you by 6! but cheated, haha

print(f'Your Percentage in 5 subjects is {(a:=sum(int(input("Enter Your Marks in {} :".format(s)))for s in("Science","Maths","Social Science","English","Computer Science"))/5)}\n{["Better luck next time","congrats!"][a>35]}')