파이썬 코드업 기초 100제 - 출력,입출력 6001-6024

벨루가 ·2022년 10월 6일

python 기초

목록 보기
1/5
post-thumbnail

코드업 기초 100제 출력,입출력 파트

출력

6001

print("Hello")

6002

print("Hello World")

6003

print('''Hello 
World''')

\n 개행 문자를 써도 되지만 코드잇에서 '''를 이용할 수도 있다고 배웠던게 기억난다.

6004

print("'Hello'")

6005

print('"Hello World"')

6006

print("\"!@#$%^&*()\'")

Python 에서 \, ", ' 순서대로 백슬래시, 큰따옴표, 작은따옴표를 print 출력하기 위해서는 해당 문자 앞에 \ (백슬래시)를 붙여서 적어줘야한다.

6007

print("\"C:\\Download\\'hello\'.py\"")

print('"C:\Download\\'hello\'.py\"') 풀이도 있음. 바깥부분의 '를 "와 구분해주고 내부를 \백슬래시를 이용하여 출력해주면 됨.

🐧 6008 : \로 구분해주기

print("print(\"Hello\\nWorld\")")

**이 문제도 마찬가지로 복잡하게 생각할것 없이 출력의 "와 일반의 "를 구분해주고 백슬래시도 \ 를 붙이면 된다.

입출력

6009

ch = input()
print(ch)

6010

n = input()
n = int(n)
print(n)

6011

n = input()
n = float(n)
print(n)

6012

a = int(input())
b = int(input())
print(a)
print(b)

6013

a = input()
b = input()
print(b)
print(a)

6014

a= float(input())
for i in range(3):
	print(a)
    

🐧6015 : split()

1 2
1
2

a, b = input().split()
a=int(a)
b=int(b)
print(a)
print(b)

input().split() 를 사용하면, 공백 을 기준으로 입력된 값들을 나누어(split) 자른다.
int(input()).split 해봤는데 안됐다. 정수로 변환해주는것은 따로 구분해주자 .

6016

a b
b a

c1,c2 = input().split()
print(c2,c1)

, 를 하면 자동으로 출력할 때 띄어줌

6017

computer science
computer science computer science computer science

s = input()
print(s,s,s)

파이썬에서 정수는 정수끼리 , 문자열은 문자열끼리 연산 가능하다.
그래서 정수의 의미를 챙기고 싶을 때 정수로 변환해줘야할 때가 있는 것.

🐧6018 : sep

3:16
3:16

a,b = input(split(':'))
print(a,b,sep = ':')

(?,?,sep = 'ㅁ') : ㅁ기호 사이에 두고 a와 b를 출력해주룜
sep 는 출력할때 쓰는 변수들간의 분류기호.
split는 입력할때 쓰는 변수들간의 분류기호. 순서대로 저장한다 로 일단 이해해보자

6019

2020.3.4
4-3-2020

y, m, d = input().split('.')
print(d,m,y,sep = '-')

3개 이상 sep 할때도 마찬가지.

🐧6020 : ''의 의미는?

000907-1121112
0009071121112 (붙여쓰시옹)

front, back = input().split('-')
print(front+''+back)
  • 모범답안 : print(front,back,sep='')

붙여쓴 ''는 리터럴리 아무것도 아닌것. 공백도 아니고 의미를 갖지도 않고!

6021

s = input()
for i in range(5) :
	print(s[i])

6022

200304
20 03 04

date = input()
print(date[0:2],date[2:4],date[4:6])

이렇게 해도 공백으로 나왔지만,

  • print(s[0:2], s[2:4], s[4:6], sep=' ') sep = ' '을 붙이는게 더 깔꼼한 풀이
  • 마지막까지 슬라이싱 하고 싶으면 date[4:] 해도 된다.

6023

17:23:57
23 시분초 중 분만 출력

h,m,s = input().split(':')
print(m)

6024

붙여서 출력하기

w1, w2 = input().split(' ')
s = w1 + w2
print(s)

0개의 댓글