import random
t = 0 #์๋ ํ์
guess = 0 #์ ๋ ฅ๋ฐ๋๊ฐ
answer = random.randint(1,100) #๋๋คํ ์
print(answer)
while 1:
print("๊ฐ์ ์ ๋ ฅ ํ์ธ์.")
guess = input()
t = t+1
if int(guess) < int(answer):
print("๋ ์๊ฐ ๋ ๋ฎ์.")
else:
if int(guess) > int(answer):
print("๋ ์๊ฐ ๋ ๋์")
else:
print("์ ๋ต~ ์ง์ง์ง")
print("์๋ ํ์๋ %d ๋ฒ ์ ๋๋ค."%t)
break
2. ๊ตฌ๊ตฌ๋จ ์์๊ฒ ์ง๊ธฐ
for i in range(1,10):
for j in range(2,10):
print('%3d'%(i*j),end='') #3d๋ 3์๋ฆฌ๋ ๋ป ์ฆ ํ์นธ์ด ๋์ด์ ธ์ ๋์ด(2์๋ฆฌ ์์ด๋ฏ๋ก)
print() #ํ์ค๋๊ธฐ
2-1. while ๋ฌธ๋ง ์ฌ์ฉํด์ ๊ตฌ๊ตฌ๋จ์ง๊ธฐ
num = 1
while num < 9:
num = num+1
num2 = 0
while num2 < 9:
num2 = num2+1
print("%d * %d = %d" %(num,num2,num*num2))
print("\n")
3. ์ผ์ ์ด์์ ์ซ์๋ง ์ถ๋ ฅ(continue)
marks=[90,25,67,80,45]
num = 0
for mark in marks:
num = num+1
if mark < 60:
continue #์ด์ดํ๊ธฐ
else:
print("%d !your good"%num)
sum =0
for i in range(0,11):
sum += i
print(sum)