IT보안관의 공부 클라우드

[구름 Level2]어려운 문제 본문

코딩 테스트/구름

[구름 Level2]어려운 문제

ㅡㅡㅡㅡㄷ 2022. 6. 20. 21:29

https://level.goorm.io/exam/49054/%EC%96%B4%EB%A0%A4%EC%9A%B4-%EB%AC%B8%EC%A0%9C/quiz/1

 

구름LEVEL

코딩테스트에서 가장 높은 비중을 차지하는 알고리즘 문제를 제작하고 풀이할 수 있는 온라인 저지 서비스입니다. 기업에서 선호하는 C, C++, 파이썬(Python), 자바(Java), 자바스크립트(Javascript) 이

level.goorm.io

import math
user_input = int(input())
a=str(math.factorial(user_input))
# print('a',a)
while 1:
	total = 0	
	for i in a:
		total += int(i)
	# print('total',total)
	if total < 10 :
		break
	else:
		a=str(total)
		# print(a)
print(total)

 

1. math 모듈을 통해 factorial 값 계산

2. 결과 값을 str() 를 통해 리스트로 저장

3. while문과 for문을 통해 각 자릿 수의 값을 계산하여 한 자리 수가 나올 때까지 반복

Comments