What does it mean for code to be reusable and what good is that?


What does it mean for code to be reusable and what good is that?


You may hear people mention DRY programming, which stands for Don’t Repeat Yourself. Simple enough, but you’d be surprised how much time and effort you’ll save by following through with it!
Often at times we’ll write code that needs some functionality repeated several times, perhaps even with different values each time. For example, if we tried to calculate the cost of a bill and tip for every meal, we’d have to write out the entire calculation each time for every different meal!
Wouldn’t it be better if we could give the cost of the meal to a function and have it handled the same way regardless of what the meal is or how much it cost?
That’s what we’ll be looking into for the next little while! Making functions that are able to do some action given some input and produce some output, all in the name of saving time and energy!


What is the meaning of the *= symbol in code??


if i search: python *=, the first search result:


google is your friend while programming.


How, depending on a given problem, should we use or not a function. I still have this little worry. Thanks in advance

This is an interesting topic.

1 Like

#example variable value
bill = 10

#shorthand to calculate bill plus tax
bill *= 1.08

#the long version (bill = 10 * 1.08)
bill = bill * 1.08

The asterisk (*) is a multiplication symbol in this usage.

For example if sales tax was 8 percent and you want to know how much something is once you add tax it could be written as follows:

bill *= 1.08

   """because if you multiply something times 1, it stays the original amount. If you multiply an amount by 1.08 it remains the same figure plus 8 percent more. so it multiplies the amount that (bill) represented"""
1 Like