형식에 맞춰 출력하기
Coddy GDScript 여정의 기초 섹션에 포함된 레슨. 92개 중 42번째.
챌린지
쉬움마지막 단계는 출력을 읽기 쉽게 만드는 것입니다. total_amount와 amount_per_person을 출력하는 두 줄을 서식 문자열과 %.2f를 사용하는 두 줄로 바꿔, 모든 금액이 소수점 이하 2자리까지 표시되게 하세요.
예를 들어 입력값이 100, 5, 2이면 프로그램은 다음을 출력합니다.
Bill Split Calculator
Total (including tip): $105.00
Each person pays: $52.50대문자, 콜론과 공백, 각 금액 앞의 $ 기호까지 포함해 텍스트를 정확히 일치시키세요. 환영 메시지와 입력값을 읽고 금액을 계산하는 코드는 그대로 두세요.
직접 해보기
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)
기초의 모든 레슨
직접 연습해 보세요: 온라인 GDScript 컴파일러