Giter VIP home page Giter VIP logo

Comments (2)

sungmin-99 avatar sungmin-99 commented on July 20, 2024 1
#3주차 숙제 시저암호 소스코드
def solution(s, n):
    a = ''
    for i in range(len(s)):
        if ord(s[i]) == 32:                                            #s[i]가 공백일때
            a = a + s[i]
        elif ord(s[i]) + n > 122:                                      #s[i] + n이 z를 넘어갈때
            a = a + chr(ord(s[i]) + n - 26)
        elif ord(s[i]) <= 90 and ord(s[i]) + n > 90:                   #s[i] + n이 Z를 넘어갈때
            a = a + chr(ord(s[i]) + n - 26)
        else:                                                          #s[i] + n이 z나 Z를 넘어가지 않고 공백도 아닐때
            a = a + chr(ord(s[i]) + n)
    return a

#3주차 숙제 알파벳 찾기
s = input()
for i in range(26):
    check = 0
    for k in range(len(s)):
        if check == 0:                   # 알파벳이 중복되는 것을 방지
            if ord(s[k]) == 97 + i:
                print(k, end=" ")
                check = 1
    if check == 0:                       # 알파벳을 찾았으면 -1을 출력 안함
        print("-1", end = " ")

from 2021-spring-python-tutoring.

sinbak avatar sinbak commented on July 20, 2024 1

과제 2번 시저암호 알파벳 찾기

def solution(s, n):
    s = list(s) # 문자를 리스트 형식으로 
    for i in range(len(s)): 
        if s[i].isupper(): # 대문자
            s[i]=chr((ord(s[i])-ord('A')+ n)%26+ord('A')) #%26을 통해 n을 0~25 유지
 
        elif s[i].islower(): #소문자
            s[i]=chr((ord(s[i])-ord('a')+ n)%26+ord('a'))
 
    answer = "".join(s) #리스트에 합치기
 
    return answer
#==================================================================================

A = input() #입력할 값
L = list(range(ord("a"), 123))
# print(ord("a")) #97
# print(ord('z')) #122
for i in L:
    print(A.find(chr(i)),end= " ")

from 2021-spring-python-tutoring.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.