
replit : 브라우저 기반 코드 편집기 (무료가입)
⚙️ 추천 세팅
Font Size large
Code Intelligence On (코드 작성 시 도움이 되는 정보나 힌트 제공)
Default Layout stacked (콘솔창이 아래로 내려가서 코드 잘림없이 한 줄에 다 볼 수 있음)
thonny : 작성한 코드를 컴퓨터가 어떻게 읽는지 확인할 수 있는 프로그램(무료다운)
print( what to print )
print("Hello world!")
...○○○"Ⓗⓔⓛⓛⓞ"○○○...
💡 에러 발생 시
- 코드 에디터가 구문 강조(syntax highlighting)한 부분을 주의깊게 보기
- 에러 문구를 그대로 복사 후 구글링하여 해결법 찾기
SyntaxError: EOL while scanning string literal
(문자열 마지막에 큰 따옴표를 넣지 않아서 발생한 에러)
print("Hello 'world!'")print('Hello "world!"')print("Hello "world!"")print("Hello \"world!\"")새 행으로 넘어감(공백 없이 사용)
# 개행 문자 미사용
print("Hello world!")
print("Hello world!")
# 개행 문자 사용
print("Hello world!"\n"Hello world!")
한 문자열 끝에 다른 문자열이 추가됨
print("Hello" + "world!") # 공백 없이 붙어서 출력
print("Hello " + "world!") # 사이에 공백 넣는 방법 1
print("Hello" + " world!") # 사이에 공백 넣는 방법 2
print("Hello" + " " + "world!") # 사이에 공백 넣는 방법 3
코드 맨 앞에 공백이나 탭을 잘못 삽입하면 들여쓰기 오류 발생
# 맨 앞에 공백 들어감
print("Hello world!")
💡 replit의 Code Intelligence 활용
실수한 부분 밑에 빨간 물결로 표시
스크롤 바에 붉은 선으로 표시
표시된 부분에 마우스를 올리면 해당 상태로 코드 실행 시 발생할 오류를 알려줌
input( A prompt for the user )
# 이름을 입력받아서 출력
input("what is your name?")
# 이름을 입력받아서 출력 함수와 함께 출력
print("Hello " + input("what is your name?"))
주석을 달은 부분은 컴퓨터가 무시하여 실행되지 않음
(코드 위에 주석으로 설명을 붙이면 나중에 봐도 쉽게 이해할 수 있다)
len( string )
# 입력받은 문자열의 길이 출력
print(len(input()))
[ 전화번호부 ]
James 0123456789
💡 변수 이름 짓는 규칙
- 숫자 사용 가능 (단, 맨 앞글자에는 불가능)
- 공백 사용 불가
- 여러 단어일 경우 _ (밑줄)이나 대문자로 단어 분리
- print, input과 같이 내장된 함수는 변수 이름으로 사용하면 안 됨(오류는 없지만 가독성을 위해)
variable = value
# 변수 name에 값 입력
name = "James"
print(name)
# 위의 변수 name의 값 "James"를 입력값으로 변경 후, name의 길이 출력
name = input("What is your name?")
length = len(name)
print(length)
Printing
두 변수에 저장된 값을 서로 교환하는 프로그램
a = input()
b = input()
temp = a # 임시 저장장소에 a의 값 임시로 저장
a = b
b = temp
print("a: " + a)
print("b: " + b)
사용자가 자란 도시와 애완동물의 이름을 합쳐서 밴드 이름을 출력하는 프로그램
🔍 유의 사항
- 입력이 활성화되면, 커서는 새로운 라인에 있어야 함
→ \n 사용
⌨️ 작성한 코드
#1. Create a greeting for your program.
print("Let's create a nice band name for your band!")
#2. Ask the user for the city that they grew up in.
city = input("type the name of the city you grew up in:\n")
#3. Ask the user for the name of a pet.
pet = input("type the name of your pet:\n")
#4. Combine the name of their city and pet and show them their band name.
print("the band name i made for you is " + "[" + city + " " + pet + "]")
#5. Make sure the input cursor shows on a new line:
# Solution: https://replit.com/@appbrewery/band-name-generator-end