☃️ 단일 파라미터 함수
# 단일 파라미터 함수
def greet_with_name(name) :
print(f"안녕하세요 {name} 님 - !")
greet_with_name("바보")
실행결과

☃️ 다중 파라미터 함수
# 다중 파라미터 함수
def greet_with(name, location) :
print(f"안녕하세요 {name} 님 - !")
print(f" {location} 사세요 ? ")
greet_with("스펀지밥", "비키니 시티")
#키워드 인자 - 순서 바꿔도 입력하려고
greet_with(location="비키니 시티", name = "뚱이")
실행결과

☃️ 소수 확인기
여기서 잠깐 !!!! 소수란 ? 1외에 자기자신으로만 나눠지는 수
# 소수 확인기
def prime_checker(num) :
is_prime = True
for i in range(2,num) :
if num % i == 0 :
is_prime = False
break
print(f"소수인가요 ? : {is_prime}")
n = int(input("숫자를 입력하시오 : "))
prime_checker(n)
실행결과

☃️ 암호화/복호화 프로그램
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
direction = input("'encode' 입력시 암호화 ,'decode' 입력시 복호화 :\n")
text = input("메시지를 입력하시오 (영어만) : \n").lower()
shift = int(input("옮길 갯수를 입력하시오 : \n"))
def caesar(di, te, shi) :
result_text = ""
for let in te :
position = alphabet.index(let)
if di == "encode" :
new_position = position + shi
if new_position > len(alphabet)-1 :
new_position -= len(alphabet)
elif direction == "decode" :
new_position = position - shi
new_letter = alphabet[new_position]
result_text += new_letter
print(f"{di} : {result_text} ")
caesar(direction,text,shift)
실행결과

'Python 🎧' 카테고리의 다른 글
| [python] 출력과 함수 - 윤년반영 월별 일수 계산/docstrings/딕셔너리 함수 결합/계산기/재귀함수 (0) | 2024.08.12 |
|---|---|
| [python] 딕셔너리 - 호출/추가/편집/지우기/리스트/중첩 (0) | 2024.08.07 |
| [python] 행맨 만들기 - 함수/모듈/반복문/배열 (0) | 2024.08.06 |
| [python] 반복문 for - 배열 가장 높은수/짝수만 더하기/fizzbuzz게임/랜덤 비밀번호 생성기 (0) | 2024.08.05 |
| [python] 배열 - append/extend 차이 (3) | 2024.08.04 |