Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.
student_marks = Hash.new 0 student_marks['Literature'] = 74 student_marks['Science'] = 89 student_marks['Math'] = 91 total_marks = 0 student_marks.each {|key,value| total_marks +=value } puts "Total Marks: "+total_marks.to_s
Output:
Total Marks: 254
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer