r/learnprogramming • u/Sky_denini • Oct 25 '26
Topic Python beginner
I’m a 1st year computer science student. I have no coding experience and my classmates can finished it like under 20 mins.
How do you code a word problem? I’m stuck of what I should code. I can somehow visualize it but I can’t put it code and I have upcoming midterm. Most of my midterm is word problem then create a function and return statement.
12
Upvotes
View all comments
1
u/SwiftQuest Oct 26 '26
What helped me with word problems was making three tiny decisions before typing anything: what goes in (those are your parameters), what has to come out (that's your return value), and what the steps are in between. Say the problem is "a store gives 10% off if you spend over 50, what's the final price?" Input is the total, output is the price, and the middle is just one if. So def final_price(total): then if total > 50: return total * 0.9, otherwise return total. Write those steps as comments first, then turn each comment into a line of code, and run it with a couple of made-up numbers so you can see where it breaks.