# 코드로 형식 지정됨
x = 100
if x > 1:
print("x는 1보다 큽니다.")
score = int(input("점수를 입력하시오: "))
if score >= 90 : # 조건이 참일 경우 들여쓰기 블록이 모두 실행됨
print("축하합니다.")
print("합격입니다.")
print("장학금도 받을 수 있습니다.")
score = int(input("점수를 입력하시오: "))
if score >= 90 : # 주의 : 들여쓰기의 크기가 다를 경우 오류가 출력됨
print("축하합니다.")
print("합격입니다.")
print("장학금도 받을 수 있습니다.")
if score >= 60:
print("합격입니다.")
else:
print("불합격입니다.")
hour = 10
if hour < 12:
print('오전입니다.')
else:
print('오후입니다.')
score = int(input("성적을 입력하시오: "))
if score >= 60:
print("합격입니다.")
else:
print("불합격입니다.")
num = int(input("정수를 입력하시오: "))
if num % 2 == 0 :
print("짝수입니다.")
else:
print("홀수입니다.")
import turtle
t = turtle.Turtle()
t.shape("turtle")
t.penup() # 펜을 올려서 그림이 그려지지 않게 한다.
t.goto(100, 100) # 거북이를 (100, 100)으로 이동시킨다.
t.write("거북이가 여기로 오면 양수입니다.")
t.goto(100, 0)
t.write("거북이가 여기로 오면 0입니다.")
t.goto(100, -100)
t.write("거북이가 여기로 오면 음수입니다.")
t.goto(0, 0) # (0, 0) 위치로 거북이를 이동시킨다.
t.pendown() # 펜을 내려서 그림이 그려지게 한다.
s = turtle.textinput("", "숫자를 입력하시오: ")
n = int(s)
if n > 0 :
t.goto(100, 100)
if n == 0 :
t.goto(100, 0)
if n < 0 :
t.goto(100, -100)
turtle.done()
try:
turtle.bye()
except:
print("bye")
age = int(input("나이를 입력하시오: "))
if age >= 15:
print("본 영화를 보실 수 있습니다.")
else:
print("본 영화를 보실 수 없습니다.")
import turtle
t = turtle.Turtle()
t.shape("turtle")
# 거북이가 그리는 선의 두께를 3으로 한다.
t.width(3)
# 거북이를 3배 확대한다.
t.shapesize(3, 3)
i=0
# 무한 루프로 진입한다. 이 루프는 Ctrl+C를 입력받아 종료된다.
while True:
command = input("명령을 입력하시오: ")
if command == "l": # 사용자가 "l"을 입력하였으면
t.left(90) # 왼쪽으로 90도 회전
t.forward(100)
if command == "r": # 사용자가 "r"을 입력하였으면
t.right(90) # 오른쪽으로 90도 회전
t.forward(100)
i+=1
if(i > 4) :
break
turtle.done()
try:
turtle.bye()
except:
print("bye")
year = int(input("연도를 입력하시오: "))
if ( (year % 4 ==0 and year % 100 != 0) or year % 400 == 0):
print(year, "년은 윤년입니다.")
else :
print(year, "년은 윤년이 아닙니다.")
import random
print("동전 던지기 게임을 시작합니다.")
coin = random.randrange(2) # randrange(2)는 0 또는 1을 반환함
if coin == 0 :
print("앞면입니다.")
else :
print("뒷면입니다.")
print("게임이 종료되었습니다.")
x, y = input('점의 좌표 x, y를 입력하시오 :').split()
x, y = float(x), float(y)
if x*x + y*y > 25 :
print('원의 외부에 있음')
else :
print('원의 내부에 있음')
num = int(input("정수를 입력하시오: "))
if num > 0:
print("양수입니다.")
elif num == 0:
print("0입니다.")
else:
print("음수입니다.")
num = int(input("정수를 입력하시오: "))
if num >= 0: # 반드시 들여쓰기를 하여 블럭을 생성
if num == 0: # 블럭내에서 세부적인 조건을 한 번 더 검사
print("0입니다.")
else:
print("양수입니다.")
else:
print("음수입니다.")
id = "ilovepython"
s = input("아이디를 입력하시오: ")
if s == id:
print("환영합니다.")
else:
print("아이디를 찾을 수 없습니다.")
import random
n = random.randint(1, 3) # 랜덤하게 1, 2, 3 중 하나의 값을 생성
if n == 1:
computer_choice = "왼쪽"
elif n == 2:
computer_choice = "중앙"
else:
computer_choice = "오른쪽"
user_choice = input("어디를 공격하시겠어요?(왼쪽, 중앙, 오른쪽) : ")
if computer_choice == user_choice:
print("공격에 실패하셨습니다.")
else :
print("축하합니다!! 공격에 성공하였습니다.")
print('컴퓨터의 수비위치 :', computer_choice)
# 도전문제 4.12 번 풀이방식
options=["왼쪽","중앙","오른쪽"]
computer_choice = random.choice(options)
user_choice = input("어디를 수비하시겠어요?(왼쪽, 중앙, 오른쪽)")
if computer_choice == user_choice:
print("수비에 성공하셨습니다.")
else:
print("수비에 실패하였습니다.")
import turtle
t = turtle.Turtle()
s = turtle.textinput("", "도형을 입력하시오: ")
if s == "사각형" :
s = turtle.textinput("","가로: ")
w = int(s)
s = turtle.textinput("","세로: ")
h = int(s)
t.forward(w)
t.left(90)
t.forward(h)
t.left(90)
t.forward(w)
t.left(90)
t.forward(h)
turtle.done()
try:
turtle.bye()
except:
print("bye")