scores = {'수학':100, '영어':90, '국어':5}
for subject,score in scores.items():
print(subject,scroe)
>> 수학 100
영어 90
국어 5
=======숫자를 1의 자리에 맞춰서 정렬하고 싶으면?! =============
print(subject.ljust(8), str(score).rjust(4))
* ljust(8) : 8칸의 공간을 확보한 뒤 왼쪽 정렬
* rjust(4) : 4칸의 공간을 확보한 뒤 오른쪽 정렬
>> 수학 100
영어 90
국어 5
for num in range(1,90):
print(str(num).zfill(3)
>> 3크기만큼 공간을 확보하고 값을 넣는데, 값이 없는 부분은 0으로 채워라
print("{0: >10}".format(500))
print("{0: >+10}".format(500))
print("{0:_>+10}".format(500))
print("{0:,}".format(10000000))
= print(f"{1000000:,}원")
print('{0:^<+30,}'.format(1000000000))
# 표준 체중 구하기(소수점 2째자리 > round(x,2))
def std_weight(height,gender):
if gender == '남자':
return height * height * 22
if gender == '여자':
return height * height * 21
height = 180
gender = '남자'
weight = round(std_weight(height/100, gender),2)
print('키{} {}의 표준 체중은 {}입니다.'.format(height,gender, weight))