-1
我正在學習ruby,並且看了看網絡,看看這有什麼問題。我曾嘗試添加間距和變量之間刪除它,我路過,但我不斷收到此錯誤:意外的','語法錯誤ruby
25: syntax error, unexpected ',', expecting ')'
student1.grades =(60,70,80)
下面是代碼:
class Student
attr_accessor :name, :age
def initialize(name,age)
@name = name
@age = age
end
def grades(math,english,science)
@math = math
@english = english
@science = science
average_grade = (math.to_i + english.to_i + science.to_i)/3
return average_grade
end
def to_s
puts "Name = #{name}"
puts "Age = #{age}"
puts self.grades
end
end
student1 = Student.new("Tom","23")
student1.grades = (60,70,80)
puts student1