공부 이야기
[3일차] Do it! 점프 투 파이썬 / 110p ~ 156p / 반복문, 함수 일부분
728x90
반응형
# 변수를 만드는 여러가지 방법
a, b = ('python', 'life')
print(a)
del(a)
a = [1, 2, 3]
b = a
a[1] = 4
print(a)
from copy import copy
b = copy(a)
print(b)
money = 1
if money:
print("택시를 타고 가라")
else:
print("걸어 가라")
x = 3
y = 2
print(x > y)
print(x<y)
print(x != y)
money = 2000
if money >= 3000:
print("택시를 타고 가라")
else:
print("걸어가라")
print(1 in [1, 2, 3])
print("j" not in 'python')
pocket = ['paper', 'cellphone', 'money']
if 'money' in pocket:
print("택시를 타고 가라")
else:
print("걸어가라")
if 'money' in pocket:
pass
else:
print("카드를 꺼내라")
pocket = ['paper', 'cellphone']
card =1
if 'money' in pocket:
print("택시를 타고 가라")
else:
if card:
print("택시를 타고 가라")
else:
print("걸어가라")
if 'money' in pocket:
print("택시를 타고 가라")
elif card:
print("택시를 타고 가라")
else:
print("걸어가라")
treeHit = 0
while treeHit < 10:
treeHit = treeHit + 1
print("나무를 %d번 찍었습니다." %treeHit)
if treeHit == 10:
print("나무 넘어갑니다")
coffee = 10
money = 300
while money:
print("돈을 받았으니 커피를 줍니다")
coffee = coffee -1
print("남은 커피의 양은 %d개 입니다." %coffee)
if not coffee:
print("커피가 다 떨어졌습니다. 판매를 중지합니다.")
break
coffee = 10
while True:
# money = int(input("돈을 넣어 주세요:"))
if money == 300:
print("커피를 줍니다.")
coffee = coffee - 1
elif money > 300:
print("거스름돈 %d를 주고 커피를 줍니다." %(money -300))
coffee = coffee -1
else:
print("돈을 다시 돌려주고 커피를 주지 않습니다.")
print("남은 커피의 양은 %d개 입니다." %coffee)
if not coffee:
print("커피가 다 떨어졌습니다. 판매를 중지합니다.")
break
a = 0
while a < 10:
a= a+1
if a%2 == 0 : continue
print(a)
test_list = ['one', 'two', 'three']
for i in test_list:
print(i)
marks = [90, 25, 67, 45, 80]
num = 0
for mark in marks:
num = num + 1
if mark >= 60:
print("%d번 학생은 합격입니다." %num)
else:
print("%d번 학생은 불합격입니다." %num)
for mark in marks:
num = num+1
if mark < 60: continue
print("%d번 학생 축하합니다. 합격입니다." %num)
a = range(10)
print(a)
sum = 0
for i in range(1, 11):
sum = sum+i
print(sum)
for i in range(2, 10):
for j in range(1, 10):
print(i*j, end = " ")
print(' ')
a = [1, 2, 3, 4]
result = []
for num in a:
result.append(num*3)
print(result)
def sum(a,b):
return a + b
a = 3
b = 4
c = sum(a, b)
print(c)
def sum(a, b) :
result = a+b
return result
a = sum(3, 4)
print(a)
def say():
return 'Hi'
a = say()
print(a)
def sum(a, b):
print("%d, %d의 합은 %d입니다." % (a, b, a+b))
sum(3, 4)
def sum_many(*args):
sum = 0
for i in args:
sum = sum+i
return sum
result = sum_many(1, 2, 3)
print(result)
def sum_mul(choice, *args):
if choice == "sum":
result = 0
for i in args:
result = result + i
elif choice == "mul":
result = 1
for i in args:
result = result * i
return result
result = sum_mul('sum', 1, 2, 3, 4, 5)
print(result)
result = sum_mul('mul', 1, 2, 3, 4, 5)
print(result)
def say_myself(name, old, man = True):
print("나의 이름은 %s입니다." %name)
print("나이는 %d살입니다." %old)
if man:
print("남자입니다.")
else:
print("여자입니다.")
say_myself("박응용", 27)
say_myself("박응용", 27, True)
a = 1
def vartest(a):
a = a+1
vartest(a)
print(a)
728x90
반응형
'공부 이야기' 카테고리의 다른 글
[aDsp] [광고x]데이터분석준전문가 2주 합격 후기 (0) | 2023.04.21 |
---|---|
일본어 단어 암기_1일차 공유 ( 왕기초/일본어왕초보/아이패드용 ) (1) | 2022.08.10 |
[1일차] Do it! 점프 투 파이썬 / 15p ~ 79p / 2.파이썬 프로그래밍 기초, 자료형 (튜플 전까지) (0) | 2022.07.11 |
4차 산업혁명과 창업 기업의 특징에 대해 (0) | 2021.12.10 |
기업분할에 대해서 (0) | 2021.12.07 |
댓글