Menu
CoddyTech

Formatted Output

Part of the Fundamentals section of Coddy's GDScript journey. Lesson 42 of 92.

challenge icon

Challenge

Easy

The last step is to make the output readable. Replace the two lines that print total_amount and amount_per_person with two lines that use a format string and %.2f, so every amount has 2 decimal places.

For example, for the inputs 100, 5 and 2, the program prints:

Bill Split Calculator
Total (including tip): $105.00
Each person pays: $52.50

Match the text exactly, including the capital letters, the colon and space, and the $ sign before each amount. Keep the welcome message and the code that reads the inputs and calculates the amounts.

Try it yourself

extends Node

func _ready():
	print("Bill Split Calculator")

	var bill_amount := float(OS.read_string_from_stdin())
	var tip_percentage := float(OS.read_string_from_stdin())
	var num_people := int(OS.read_string_from_stdin())

	var tip_amount := (tip_percentage / 100) * bill_amount
	var total_amount := bill_amount + tip_amount
	var amount_per_person := total_amount / num_people

	print(total_amount)
	print(amount_per_person)

All lessons in Fundamentals

Practice on your own: Online GDScript compiler