colab link: control
money = 2000
if money > 5000:
print("택시를 타고 가요~")
print("음료를 사먹어요.")
else:
print("걸어가요.")
print("더워요. 샤워할래요.")
> 걸어가요.
더워요. 샤워할래요.
pocket = ['paper', 'cellphone', 'money']
if 'money' in pocket:
print("택시를 타고 가라.")
elif 'cellphone' in pocket:
print("택시를 타고 가라.")
else:
print("걸어 가라.")
> 택시를 타고 가라.
if 'money' in pocket:
pass
else:
print("일자리를 구한다.")
>
한줄로 간단하게 표현 가능
if 'money' in pocket: pass
else:
print("일자리를 구한다.")
>
score = 70
message = "success" if score >= 60 else "failure"
print(message)
> success
sum = 0
number = 0
while sum < 10000:
number += 1
sum += number
print(number)
> 141
sum = 0
number = 0
while sum < 4000:
number += 1
sum += number
if number >= 100:
break
print(sum)
print(number)
> 4005
89
sum = 0
for x in range(1, 142):
sum+=x
print(sum)
> 10011
marks = [90, 25, 67, 45, 80]
number = 0
for mark in marks:
number = number + 1
if mark < 60:
continue
print("%d번 학생 축하합니다. 합격 입니다." % number)
> 1번 학생 축하합니다. 합격 입니다.
3번 학생 축하합니다. 합격 입니다.
5번 학생 축하합니다. 합격 입니다.
print(list(range(0, 20, 4)))
> [0, 4, 8, 12, 16]
for x in range(1,11):
for y in range(x):
print("*", end='')
print()
> *
**
***
****
*****
******
*******
********
*********
**********
for x in range(1,11):
for y in range(11-x):
print("*", end='')
print()
> **********
*********
********
*******
******
*****
****
***
**
*
for x in range(1,11):
for y in range(10-x):
print(" ", end='')
for y in range(x):
print("*", end='')
print()
> *
**
***
****
*****
******
*******
********
*********
**********
for x in range(1,11):
for y in range(x-1):
print(" ", end='')
for y in range(11-x):
print("*", end='')
print()
> **********
*********
********
*******
******
*****
****
***
**
*
for x in range(1,11):
for y in range(10-x):
print(" ", end='')
for y in range(x):
print("*", end='')
for y in range(x-1):
print("*", end='')
print()
> *
***
*****
*******
*********
***********
*************
***************
*****************
*******************
for x in range(1,10):
for y in range(x):
print(" ", end='')
for y in range( 10 -x):
print("*", end='')
for y in range( 9 -x):
print("*", end='')
print()
> *****************
***************
*************
***********
*********
*******
*****
***
*
for x in range(1,11):
for y in range(10-x):
print(" ", end='')
for y in range(x):
print("*", end='')
for y in range(x-1):
print("*", end='')
print()
for x in range(1,10):
for y in range(x):
print(" ", end='')
for y in range( 10 -x):
print("*", end='')
for y in range( 9 -x):
print("*", end='')
print()
> *
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
for x in range(1,21):
if (x < 11):
for y in range(10-x):
print(" ", end='')
for y in range(x):
print("*", end='')
for y in range(x-1):
print("*", end='')
else:
for y in range(x-10):
print(" ", end='')
for y in range(20-x):
print("*", end='')
for y in range(19-x):
print("*", end='')
print()
> *
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*