iT邦幫忙

2019 iT 邦幫忙鐵人賽

DAY 12
0
影片教學

懶人寫寫 BOT系列 第 12

Day 12

  • 分享至 

  • xImage
  •  

嗨,我是 Fly,用 Ruby 寫 Chatbot 並挑戰30天分享心得
為確保不會沒靈感
每日含 Ruby 解題增加內容
https://www.hackerrank.com/domains/tutorials/30-days-of-code

Day 12: Inheritance

  • Use super to learn parent func
  • average = @score.sum/@score.size
class Person
	def initialize(firstName, lastName, id)
		@firstName = firstName
		@lastName = lastName
		@id = id
	end
	def printPerson()
		print("Name: ",@lastName , ", " + @firstName ,"\nID: " , @id)
	end
end


class Student <Person
    def initialize(firstName, lastName, id, score)
      super(firstName, lastName, id)
      @score = score
    end

    def calculate
      total = @score.sum/@score.size
      if total < 101 && total > 89
        'O'
      elsif total < 90 && total > 79
        'E'
      elsif total < 80 && total > 69
        'A'
      elsif total < 70 && total > 54
        'P'
      elsif total < 55 && total > 40
        'D'
      else
        'T'
      end
    end
end


input = gets.split()
firstName = input[0]
lastName = input[1]
id = input[2].to_i
numScores = gets.to_i
scores = gets.strip().split().map!(&:to_i)
s = Student.new(firstName, lastName, id, scores)
s.printPerson           
print("\nGrade: " + s.calculate)

上一篇
Day 11
下一篇
Day 13
系列文
懶人寫寫 BOT30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言