파이썬 수업에서 예시를 들었던 것을 보고 바로 해보고 싶었던 것은 로또번호 추첨기였다.
3회수강까지 보고 작업한 것은
import random
print(random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"]))
print(random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"]))
print(random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"]))
print(random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"]))
print(random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"]))
print(random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"]))
이렇게 였는데 역시나 이런 노가다는 필요하지 않았다
import random
for X in range(6):
print(random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"]))
요렇게 하면 깔끔하게 로또 추첨기가 완성될 수 있겠다
추가로 들여쓰기가 매우 중요하며,
time.sleep(1)
break =(clt+c)
요것도 배움
추가로 변수화 할 수도 있는데
변수는 =로 지정하면 된다. 파이썬은 HTML이랑 좀 다르게 들여쓰기 생활화 순서대로 코딩이 먹는 특징이 있어보인다.
지금까진 배운 지식을 응용해서 만들었는데 for 구문 이해가 좀 부족해보인다. 이는 리뷰로 다시 공부를 해야겠다
import random
for X in range(6):
lottonumber = random.choice(["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45"])
print(lottonumber)
list는 []
dictionary는 {}
변수[""] = "" 추가
del 변수[""]는 삭제
len(변수)는 갯수
리스트 안(XX[0])는 몇번째꺼 활성
.append("xx")는 추가
이게 최종 값이 도출되는 것에서 0 1 2 3의 개념으로 접근되니까 append를 이용하여 추가하면 후속에 대한 번호를 지워야한다
일단 이번 강의는 대략적인 이해는 되는데 디테일하게 내가 인지했다는 느낌이 덜 드는 것 같다.
복습을 해보려고 하다가 '같이푸는파이썬'자료를 보니 복습의 개념과 거의 유사해 보여서
이 수업을 듣고 지금 수업을 다시 보면 이해가 더 잘 될 것 같다.
기초까지는 어찌저찌 할 수 있겠는데.. 이거 난이도 올라가면...
심화 파이썬 수업을 가장 마지막에 들어야 겠다.
foods = ["된장찌개", "피자", "제육볶음"]
for x in range(3):
print(foods[x])
for x in foods:
print(x)
요거는 좀 헷갈림
8강 어려움
63
lunch = ["된장찌개", "피자", "제육볶음", "짜장면"]
import random
import time
lunch = ["된장찌개", "피자", "제육볶음", "짜장면"]
while True:
print(lunch)
item = input("음식을 추가 해주세요 : ")
if(item == "q"):
break
else:
lunch.append(item)
print(lunch)
set_lunch = set(lunch)
while True:
print(set_lunch)
item = input("음식을 삭제해주세요 : ")
if(item == "q"):
break
else:
set_lunch = set_lunch - set([item])
print(set_lunch, "중에서 선택합니다.")
print("5")
time.sleep(1)
print("4")
time.sleep(1)
print("3")
time.sleep(1)
print("2")
time.sleep(1)
print("1")
time.sleep(1)
print(random.choice(list(set_lunch)))
total_dictionary = {}
while True:
question = input("질문을 입력해주세요 : ")
if question == "q":
break
else:
total_dictionary[question] = ""
for i in total_dictionary:
print(i)
answer = input("답변을 입력해주세요 : ")
total_dictionary[i] = answer
print(total_dictionary)
####
...