MapleStory Finger Point

๐Ÿ’Ž Python/Python ๊ฐœ๋…์ •๋ฆฌ

๋ฌธ์ž์—ด

HYEJU01 2024. 4. 8. 00:54

โ–ถ ๋ฌธ์ž์—ด ๊ฐœ๋…

  • ๋ฌธ์ž์—ด์„ '' , "" ์œผ๋กœ ๋ฌถ์–ด์„œ ํ‘œํ˜„ํ•จ ⇒ print()๋ฅผ ํ•˜๋ฉด ์ž‘์€๋”ฐ์˜ดํ‘œ('')๋กœ ํ‘œ์‹œ๋œ๋‹ค.
  • ๋ฆฌ์ŠคํŠธ๋Š” ๋Œ€๊ด„ํ˜ธ [] ↔ ๋ฌธ์ž์—ด์€ ์ž‘์€๋”ฐ์˜ดํ‘œ '' ์ถœ๋ ฅ๋จ
    • ๊ธฐํ˜ธ๋Š” ๋ฌธ์ž์—ด์—ฐ๊ฒฐ
    • ๋Š” ๋ฌธ์ž์—ด ๋ฐ˜๋ณต
aa=[1,2,3]
ss="ํŒŒ์ด์ฌ๊ฟ€์žผ"

aa[0]   #1
aa[1:3] #[2,3]

ss[0]   #'ํŒŒ'
ss[1:3] #'์ด์ฌ'
#๋ฌธ์ž์—ด ๋ง์…ˆ
ss = 'ํŒŒ์ด์ฌ' + '์ตœ๊ณ '    #'ํŒŒ์ด์ฌ์ตœ๊ณ '

#๋ฌธ์ž์—ด ๊ณฑ์…ˆ
ss = 'ํŒŒ์ด์ฌ' * 3    #'ํŒŒ์ด์ฌํŒŒ์ด์ฌํŒŒ์ด์ฌ'

[SELF STUDY 8-1]

ss = 'ํŒŒ์ด์ฌ์€์™„์ „์žฌ๋ฏธ์žˆ์–ด์š”'

sslen = len(ss)
for i in  range(0,sslen) :
    if i % 2 == 0 :
        print(ss[i],end='')
    else :
        print('#',end='')

#end = '' ๋Š” ์ค„ ๋ฐ”๋€Œ๋Š”๊ฑฐ ๋ฐฉ์ง€ํ•ด์ฃผ๋Š” ๊ฒƒ

[ํ”„๋กœ๊ทธ๋žจ 1]

## ๋ณ€์ˆ˜ ์„ ์–ธ ๋ถ€๋ถ„ ##
inStr, outStr = "", ""
count, i = 0, 0

## ๋ฉ”์ธ ์ฝ”๋“œ ๋ถ€๋ถ„ ##
inStr = input("๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์„ธ์š” : ")
count = len(inStr)

for i in range(0, count) :
     outStr += inStr[count - (i + 1)]

print("๋‚ด์šฉ์„ ๊ฑฐ๊พธ๋กœ ์ถœ๋ ฅ --> %s" % outStr)

โ–ถ ๋ฌธ์ž์—ด ํ•จ์ˆ˜

  • len() ํ•จ์ˆ˜ : ๋ฆฌ์ŠคํŠธ or ๋ฌธ์ž์—ด ๊ฐœ์ˆ˜ ์…ˆ
  • ๋ฌธ์ž์—ดํ•จ์ˆ˜ (๋Œ€์†Œ๋ฌธ์ž๋ณ€ํ™˜) : upper(),lower(),swapcase(),title()
  • (๋ฌธ์ž์—ด์ฐพ๊ธฐ) : count(), find() rfind() ๋“ฑ๋“ฑ...
  • (๋ฌธ์ž์—ด ๊ณต๋ฐฑ,์‚ญ์ œ,๋ณ€๊ฒฝ) strip(), rstrip() ๋“ฑ๋“ฑ...
  • # 8-4 ์‘์šฉ ( ๋ฌธ์ž์—ด ๊ณ„์† ๋ฐ›๊ธฐ ) while (1) : inStr=input(str()) outStr= "" for i in range (0,len(inStr)) : if inStr[i] != ' ': outStr += inStr[i] print("์›๋ž˜ ๋ฌธ์ž์—ด ===>" + '['+inStr+']') print("๊ณต๋ฐฑ ์‚ญ์ œ ๋ฌธ์ž์—ด ==> " + '['+outStr+']') if inStr == 'Q' : break;

[SELF STUDY 8-2]

#[SELF STUDY 8-2]
while (1) :
    inStr=input(str())
    outStr= ""

    for i in range (0,len(inStr)) :
        if inStr[i] != "<" and inStr[i] !=">":
            outStr += inStr[i]

    print("์›๋ž˜ ๋ฌธ์ž์—ด ===>" + '['+inStr+']')
    print("๊ณต๋ฐฑ ์‚ญ์ œ ๋ฌธ์ž์—ด ==> " + '['+outStr+']')
    
    if inStr == 'Q' :
        break;

[SELF STUDY 8-3]

#[SELF STUDY 8-3]

ss = input(str("๋ฌธ์ž์—ด ์ž…๋ ฅ :"))

if ss.isalpha() == True:
    print("๊ธ€์ž์ž…๋‹ˆ๋‹ค")
elif ss.isdigit()  == True :
    print("์ˆซ์ž์ž…๋‹ˆ๋‹ค.")
elif ss.isalnum() == True :
    print("๊ธ€์ž+์ˆซ์ž์ž…๋‹ˆ๋‹ค")
else :
    print("๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.")

[ํ”„๋กœ๊ทธ๋žจ 2]

import turtle
import random
from tkinter.simpledialog import *

##์ „์—ญ ๋ณ€์ˆ˜ ์„ ์–ธ ๋ถ€๋ถ„##
inStr = ''
swidth, sheight = 300, 300
tX,tY,txtSize =[0] * 3

##๋ฉ”์ธ ์ฝ”๋“œ ๋ถ€๋ถ„##
turtle.title('์ž„ํ˜œ์ฃผ ๋ฌธ์ž์—ด ์—ฐ์Šต')
turtle.shape('turtle')
turtle.setup( width = swidth + 50, height = sheight + 50)
turtle.screensize( swidth, sheight)
turtle.penup()

inStr = askstring('๋ฌธ์ž์—ด ์ž…๋ ฅ','๊ฑฐ๋ถ์ด ์“ธ ๋ฌธ์ž์—ด์„ ์ž…๋ ฅ')

for ch in inStr :
    tX = random.randrange(-swidth / 2, swidth / 2)
    tY = random.randrange(-sheight / 2,sheight / 2)
    r = random.random(); g = random.random(); b = random.random()
    txtSize = random.randrange(10,50)
    
    turtle.goto(tX,tY)
    
    turtle.pencolor((r,g,b))
    turtle.write(ch,font=('๋ง‘์€ ๊ณ ๋”•',txtSize,'bold'))
    
turtle.done()

[์‘์šฉ ์˜ˆ์ œ 01]

##์ „์—ญ ๋ณ€์ˆ˜ ์„ ์–ธ ๋ถ€๋ถ„##

inStr, outStr = "", ""
ch = ""
count, i =0, 0

## ๋ฉ”์ธ ์ฝ”๋“œ ๋ถ€๋ถ„ ##

if __name__ == "__main__" :
	inStr = input("๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์„ธ์š”")
	count = len(inStr)

	for i in range(0,count):
		ch = inStr[i]
		if (ord(ch) >= ord("A") and ord(ch) <= ord("Z")) :
			newCh = ch.lower()
		elif (ord(ch) >= ord("a") and ord(ch) <= ord("z")) :
			newCh = ch.upper()
		else :
			newCh = ch
		
		outStr += newCh

print("๋Œ€์†Œ๋ฌธ์ž ๋ณ€ํ™˜ ๊ฒฐ๊ณผ -> %s" %outStr)

[practice 7]

outStr = ''
inStr = input('๋ฌธ์ž์—ด-->')

for i in range(0, len(inStr)):
  if inStr[i].isdigit() == False:
    outStr += inStr[i]

print('์ˆซ์ž ์ œ๊ฑฐ-->', outStr)