coding for food
-
[Ruby] Conditionalscoding for food 2022. 7. 20. 14:20
def is_div_by_5(number) if number % 5 == 0 return true # boolean 으로 적어야함, "string" 과 구분할 것, return 값을 되돌려줌. else return false end end puts is_div_by_5(10) # => true puts is_div_by_5(40) # => true puts is_div_by_5(42) # => false puts is_div_by_5(8) # => false if is_div_by_5(11) puts "available divied by 5" # put은 프린트 end
-
[Ruby] Conditionalscoding for food 2022. 7. 20. 13:22
num = 8 if num > 0 puts "positive" end if num % 2 = 0 puts "even" end 조건이 두개 이므로 값이 두개가 나옴 ---------------------------------------------------------------------- num = 8 if num > 0 puts "positive" elsif num % 2 = 0 puts "even" end 두갈래의 길 중에 첫번째 길 (if) 이 맞을 경우 결과값은 한개가 나온다. if 가 아니면 elsif의 길을 갈수 있는 기회가 생김. if is true, go down this path and print out positive. I don't even both checking this condi..
-
[Ruby] Methodscoding for food 2022. 7. 19. 14:28
def say_hello(person1, person2) puts "Hello" + person1 + " and " + person2 + "." end say_hello("Kim", "Carl") Hello Kim and Carl. ------------------------------------------------ def calc_avarage (num1, num2) sum = num1 + num2 avg = sum / 2 return avg # The return keyword lets a method call evaluate to a value end result = calc_avarage (5, 10) puts result + 1 return은 돌려주는 것, 값을 입력했을 때 되돌려주는 값으로 ..
-
[Ruby] Printing Datacoding for food 2022. 7. 19. 09:36
puts : 제일 기본적으로 쓰이는 것. print : 라인없이 기본적으로 만들어짐. print "hello" print "world" # the code above would print: # helloworld 매뉴얼로 "\n", new line을 만들 수 있다. "\t"를 사용해서 whitespace(tab)띄워쓰기를 할 수 있음. print "hello\n" print "\tworld\n" # the code above would print: # hello # world p : 데이터 타입을 구분해서 보여진다. p "hello" p 'goodbye' p "42" p 42 # the code above would print: # "hello" # "goodbye" # "42" # 42 p "42" 와..
-