if
weather = input("์ค๋ ๋ ์จ๋ ์ด๋์?") #์ฌ์ฉ์ ์ธํ์ ํ์๋ก ํจ
if weather == "๋น" or weather == "๋":
print("์ฐ์ฐ์ ์ฑ๊ธฐ์ธ์")
elif weather == "๋ฏธ์ธ๋จผ์ง":
print("๋ง์คํฌ๋ฅผ ์ฑ๊ธฐ์ธ์.")
else:
print("์ค๋น๋ฌผ ํ์์์ด์.")
for
for waiting_no in range(1,6): #1, 2, 3, 4, 5
print("๋๊ธฐ๋ฒํธ : {0}".format(waiting_no))
#์คํ๋ฒ
์ค ์๋
starbucks = ["์์ด์ธ๋งจ", "ํ ๋ฅด", "์์ด์ ๊ทธ๋ฃจํธ"]
for cumstomer in starbucks:
print("{0}๋, ์ปคํผ๊ฐ ์ค๋น๋์์ต๋๋ค.".format(customer))
while
#5๋ฒ์ด๋ ๋ถ๋ ๋๋ฐ ์๋ํ๋๋ฉด ์ปคํผ ๋ฒ๋ฆฌ๋ ์ ์ฑ
customer = "ํ ๋ฅด"
index = 5
while index >= 1:
print("{0}๋, ์ปคํผ๊ฐ ์ค๋น๋์์ต๋๋ค. {1}๋ฒ ๋จ์์ด์.".format(customer, index))
index -=1
if index == 0
print("์ปคํผ๋ ํ๊ธฐ์ฒ๋ถ๋์์ต๋๋ค.")
customer = "์์ด์ธ๋งจ"
index = 1
while True:
print("{0}๋, ์ปคํผ๊ฐ ์ค๋น๋์์ต๋๋ค. ํธ์ถ{1}ํ.".format(customer, index))
index += 1 #๋ฌดํ๋ฃจํ
customer = "ํ ๋ฅด"
person = "Unknown"
while person != customer :
print("{0}๋, ์ปคํผ๊ฐ ์ค๋น๋์์ต๋๋ค.".format(customer))
person = input("์ด๋ฆ์ด ์ด๋ป๊ฒ ๋์ธ์?")
continue and break
absent = [2, 5] #2๋ฒ๊ณผ 5๋ฒ ๊ฒฐ์
no_book = [7] #์ฑ
์ ์๊ฐ๊ณ ์ด
for student in range(1, 11): #1~10๊น์ง ์ถ์๋ฒํธ
if student in absent:
continue
elif student in no_book:
print("์ค๋ ์์
์ฌ๊ธฐ๊น์ง. {0}๋ ๊ต๋ฌด์ค๋ก ๋ฐ๋ผ์.format(student))
break
print("{0}์ผ, ์ฑ
์ ์ฝ์ด๋ด".format(stduent))
ํ ์ค for
#์ถ์๋ฒํธ๊ฐ 1 2 3 4 ๊ฐ ์๋๋ฐ, ์์ผ๋ก 100์ ๋ถ์ด๊ธฐ๋ก ํจ
students = [1, 2, 3, 4, 5]
students [ i+100 for i in students]
#ํ์ ์ด๋ฆ์ ๊ธธ์ด๋ก ๋ณํ
students = ["Iron man", "Thor". "I am groot"]
students = [len(i) for i in students]
#ํ์ ์ด๋ฆ์ ๋๋ฌธ์๋ก ๋ณํ
students = ["Iron man", "Thor". "I am groot"]
students = [i.upper() for i in students]
Quiz
ํ์ ์๋น์ค๋ฅผ ์ด์ฉํ๋ ํ์ ๊ธฐ์ฌ๋
50๋ช
์ ์น๊ฐ๊ณผ ๋งค์นญ ๊ธฐํ๊ฐ ์์ ๋, ์ด ํ์น ์น๊ฐ ์๋ฅผ ๊ตฌํ๋ ํ๋ก๊ทธ๋จ์ ์์ฑํ์์ค.
์กฐ๊ฑด1: ์น๊ฐ๋ณ ์ดํ ์์ ์๊ฐ์ 5~50๋ถ ์ฌ์ด์ ๋์๋ก ์ ํด์ง๋๋ค.
์กฐ๊ฑด2: ๋น์ ์ ์์์๊ฐ 5~15๋ถ ์ฌ์ด์ ์น๊ฐ๋ง ๋งค์นญํด์ผ ํฉ๋๋ค.
์ถ๋ ฅ๋ฌผ ์์ :
[ ] 1๋ฒ์งธ ์๋ (์์์๊ฐ : 20๋ถ)
.
.
.
์ด ํ์น ์น๊ฐ : 2๋ถ
๋์ ํ์ด
๋๋ณด๊ธฐ
from random import *
count = 0
for clients in range(1, 51):
time = randint(5, 50)
if 5 <= time <= 15:
ox = "O"
count += 1
print("[{0}] {1}๋ฒ์งธ ์๋ (์์์๊ฐ: {2}๋ถ)".format(ox,clients,time))
else:
ox = " "
print("[{0}] {1}๋ฒ์งธ ์๋ (์์์๊ฐ: {2}๋ถ)".format(ox, clients, time))
print("์ด ํ์น ์น๊ฐ : {}๋ถ".format(count))
ํด์ค
๋๋ณด๊ธฐ
from random import *
cnt = 0 #์ด ํ์น ์น๊ฐ ์
for i in range(1, 51):
time = randrange(5, 51)
if 5 <= time <= 15:
print("[O] {0}๋ฒ์งธ ์๋ (์์์๊ฐ : {1}๋ถ))".format(i, time))
cnt += 1
else:
print("[ ] {0}๋ฒ์งธ ์๋ (์์์๊ฐ : {1}๋ถ))".format(i, time))
print("์ด ํ์น ์น๊ฐ : {0}".format(cnt))