Pytyon & Ruby & Atom

함수 (function)

함수란 무엇인가?

함수 만들기

Python

def a3():
    print('aaa')
a3()

Ruby

def a3()
    puts('aaa')
end
a3()

실행결과

aaa

Python | Ruby 

리턴값

Python

def a3():
    return 'aaa'
print(a3())

Ruby

def a3()
    return 'aaa'
end
puts(a3())

실행결과

aaa

Python | Ruby 

입력값

 Python

def a(num):
    return 'a'*num
print(a(3))

Ruby

def a(num)
    return 'a'*num
end
puts(a(3))

실행결과

aaa

Python | Ruby

여러개의 입력값

 Python

def make_string(str, num):
    return str*num
print(make_string('b', 3))

Ruby

def make_string(str, num)
    return str*num
end
puts(make_string('b', 3))

실행결과

aaa

Python | Ruby

로그인 애플리케이션 (루비)

puts("아이디를 입력해주세요")
input_id = gets.chomp()

def login(_id)
  members = ['egoing', 'k8805', 'leezche']
  for member in members do
      if member == _id
          return true
      end
  end
  return false
end

if login(input_id)
  puts('Hello, '+input_id)
else
  puts('Who are you?')
end

 ideone.com

로그인 애플리케이션 (파이썬)

input_id = input("아이디를 입력해주세요.\n")
def login(_id):
    members = ['egoing', 'k8805', 'leezche']
    for member in members:
        if member == _id:
            return True
    return False
if login(input_id):
    print('Hello, '+input_id)
else:
    print('Who are you?')

ideone.com

참고

github.com

댓글

댓글 본문
버전 관리
egoing
현재 버전
선택 버전
graphittie 자세히 보기