반응형
-
[파이썬]while, for 반복문 탈출과 계속하기 - break, continue 이번 포스팅에서는 while과 for 같은 반복문에서 조건문이 True인 경우에도 반복문을 탈출할 수 있게 해주는 break와 반복문의 시작 지점으로 돌아가게 해주는 continue에 대해 알아본다. 반복문 강제로 탈출하기 - break break로 반복문 강제로 탈출하기 while문의 조건문이 True일 경우에도 break로 while문을 빠져나올 수 있다. count = 0 while True: count += 1 print('현재 카운트 %d' %count) if count == 5: break print('while문 탈출') #결과 출력 현재 카운트 1 현재 카운트 2 현재 카운트 3 현재 카운트 4 현재 카운트 5 while문 탈출 위 예문을 보면 조건문은 항상 True이기 때문에 while문..
-
[파이썬]파일 읽고 쓰기 - open, close, with 파이썬에서는 사용자로부터 값을 입력받거나, 화면상에 값을 출력하는 방법만 있는 것이 아니라 파일을 통해 입력을 받거나 출력을 할 수도 있다. 이번 포스팅에서는 파이썬의 내장 함수 open을 통해 파일을 읽고 쓰는 방법을 알아보자. 쓰기 모드로 파일 열기 - open, write, close 파일 생성하기 파일을 쓰기 전에 파일을 생성하는 방법을 알아보자. 파이썬의 내장 함수 open을 사용하면 굉장히 쉽게 파일을 생성할 수 있다. open 함수는 파일 객체 = open("파일이름.확장자", "읽기 모드")의 형태로 사용하면 된다. 다음 코드를 실행하여 파일을 생성해보자. f = open("new_file.txt", mode="w") f.close() 읽기 모드에 "w"를 입력하면 파일 쓰기모드가 되면서 ..
-
[파이썬]숫자 맞추기 게임 만들기 이번 포스팅에선 파이썬을 활용하여 1부터 99까지의 랜덤한 숫자를 10번 안에 찾는 게임을 만들어보자. 숫자 맞추기 게임 만들기 랜덤한 수 만들기 1에서 99까지 랜덤한 수를 만들어 보자. random 라이브러리를 활용해보자. import random num_random = random.randint(1, 99) 반복문 만들기 그 다음 10번 동안 문제를 내는 반복문을 만들어보자. coin = 10 while coin: coin-=1 print("남은 코인 개수: {}".format(coin)) 조건문 만들기, 입력받기 coin = 10 num = 0 while coin: coin -= 1 num = int(input("1~99 사이의 숫자를 맞춰보세요")) if num == num_random: pri..
-
25.09.24 - Festival English 1. What is your favorite festival, and why do you enjoy it? - I love watching game competitions, particularly Legue of Legend which is an MOBA game. Around the end of year, The World Chapionship is held where many different teams from other countries participate in and play at each other. As I grow older and older, the more I enjoy at home than outside. I like watching the game matches from TV w.. -
25.09.23 - Placing an order at a cafe 1. What type of coffee do you usually order at a cafe, and why? - I usally order an iced americano when I go to a cafe. I actually used to have frappuchino everytime I was at a cafe, but since I made up my mind to cut back on sugar, I haven't had frappuchino things very much. Actually I'm trying to cut back on caffeine too, but I have no other options but americano. The main reason I go to cafes.. -
25.09.23 - Grocery shopping 1. What do you usually buy when you go grocery shopping? - I always grab some zero-sugar drinks like Pepsi Zero Lime. It's my absolute favorite. I also like to check out the deli section, especially right before the store closes, because that's when they have a lot of food on sale. The food always smells amazing and is cheaper, so I usually end up buying some, even though it's often not as tasty..
반응형