← Back to all posts

Hello everybody i am new coder and i was curious how you could make lines 9 to 11 in one expression using the same calculation.

As well where could you add data validation points to check data is correct

many thanks

hotnewtop
[deleted]

percentage_decimal = tip_percentage / 100; tip_total = bill_total percentage_decimal;tip_total = bill_total percentage_decimal;bill_total = bill_total + tip_total;cost_per_person = bill_total / people

--

This is all on one line

TurtleAndrew (211)

Is this what you want?

bill_total = bill_total + tip_percentage / 100

percentage_decimal = tip_percentage / 100
tip_total = bill_total * percentage_decimal
bill_total = bill_total + tip_total

SixBeeps (5231)

If you want to simplify the expression down to one line, replace each variable on line 11 with it's expression. I'll complete the first step to show you what I mean:

``````# This is the original
percentage_decimal = tip_percentage / 100
tip_total = bill_total * percentage_decimal
bill_total = bill_total + tip_total

# This is code after one replacement
percentage_decimal = tip_percentage / 100
bill_total = bill_total + (bill_total * percentage_decimal)``````