728x90
문제
Captain Jack decides to to take over a rival’s ship.
He needs to send his henchmen over on rowboats that can hold 6 pirates each.
You will help him count out pirates in groups of 6.
The last rowboat may have fewer than 6 pirates.
To make your task easier each pirate has been assigned a number from 1 to N.
https://www.acmicpc.net/problem/5300
입력
The input will be N, the number of pirates you need to send over on rowboats.
출력
The output will be the number of each pirate separated by spaces, with the word ”Go!” after every 6th pirate, and after the last pirate.
예제
# input
10
# output
1 2 3 4 5 6 Go! 7 8 9 10 Go!
# input
18
# output
1 2 3 4 5 6 Go! 7 8 9 10 11 12 Go! 13 14 15 16 17 18 Go!
문제 풀이
# 1
N = int(input())
for i in range(1, N+1):
print(i, end = ' ')
if i % 6 == 0 or i == N:
print('Go!', end = ' ')
# 2
N = int(input())
ans = []
for i in range(1,N+1):
ans.append(i)
if i % 6 == 0 or i == N:
ans.append('Go!')
print(' '.join(map(str, ans)))
파이썬을 독학하시는 분들에게 도움이 되길 바라며,
혹 더 좋은 방법이 있거나 오류가 있다면 편하게 말씀 부탁드립니다.
728x90