''' if '''
#############################################################
a = True
if a:
print('joon') # joon 출력
#############################################################
b = int(input('원하는 값을 입력: '))
if b>4:
print('%d는 4보다 크다.'%b)
else:
print('%d는 4보다 작거나 같다.'%b)
#############################################################
a = int(input("첫 번째 값을 입력하세요."))
b = int(input('두 번째 값을 입력하세요.'))
c = int(input('세 번째 값을 입력하세요.'))
if a>b and a>c:
num_max=a
elif b>a and b>c:
num_max=b
elif c>a and c>b:
num_max=c
if a<b and a<c:
num_min=a
elif b<a and b<c:
num_min=b
elif c<a and c<b:
num_min=c
print(f'최대값은 {num_max}이며 최소값은 {num_min}이다.')
#############################################################
''' for '''
i = 0
for i in range(1,10): # range(초기값,끝값,x) 1<=i<10
print("i = %d"%i) # 1~9까지 출력된다. 증감값이 자동으로 1로 지정됨
j = 10
for j in range(10): # range(x,끝값,x), 0<=j<10
print(f'j={j}') # 1~9까지 출력된다. 초기값과 증감값이 자동으로 1로 지정됨
k = 0
for k in range(0,10,2): # range(초기값,끝값,증감값)
print('k={}'.format(k)) # 0,2,4,6,8 출력된다.
a = ['one','two','three']
for l in a:
print(l)
print(type(l))
''' while '''
treeHit = 0
while treeHit < 10:
treeHit += 1
print("나무를 %d번 찍었다."%treeHit) # '나무를 (1~10)번 찍었다.' 차례로 출력
if treeHit==10:
print("나무가 넘어갔다.") # '나무가 넘어갔다.' 출력됨
################################################################################################
num = 0
prompt = "1.Add | 2.Del | 3.List | 4.Quiz | 5.Name : "
while num != 4:
num = int(input('값을 입력하세요.'))
if num>= 5: # 4 또는 5이상 값을 넣어줄때까지 무한 반복됨
break # 4이상 값을 넣어주면 빠져나온다.
################################################################################################
coffee=5
money=300
while money:
coffee -=1
print('남은 커피 양은 %d잔입니다.'%coffee)
if not coffee:
print("남은 커피 모두 소진됨")
break
################################################################################################
price = 300
coffee = 10
while True:
money = int(input('돈을 넣으시오.: '))
if money < price:
print('돈이 {}만큼 부족합니다. 남은 커피는 {}잔입니다.'.format((300-money),coffee))
elif money == price:
coffee -= 1
print(f'주문하신 커피 1잔입니다. 남은 커피는 {coffee}잔입니다.')
else:
coffee -= 1
print('주문하신 커피 1잔입니다. 거스름 돈은 %d원이며 남은 커피는 %d잔입니다.'%(money-price,coffee))
if not coffee:
print("커피가 모두 소진되었습니다.")
break
################################################################################################
a,b =2,1
while b<10:
print('%dx%d=%d\n'%(a,b,a*b))
b+=1
################################################################################################
a = int(input('원하는 구구단 수 입력'))
i = 1
for i in range (1,10,1):
print('%dx%d=%d'%(a,i,a*i))
################################################################################################
a=0
sum=0
for a in range(1,1001,1):
if a%3==0:
sum+=a
print(f'{sum}')
################################################################################################
a=0
sum=0
while a<1001:
a+=1
if a%3==0:
sum+=a
print('{}'.format(sum))