๐Ÿ“œ
B.TECH III YEAR โ€ข II SEMESTER โ€ข R22

Scripting Languages - Lab Manual

Scripting Languages Laboratory โ€ข Program 10 Solution

๐Ÿ“˜ R22 Regulation ๐ŸŽ“ III Year ๐Ÿ“š II Semester ๐Ÿ“œ Scripting Languages ๐Ÿ’Ž Ruby โ€ข TCL โ€ข Perl ๐Ÿงช Lab Program
Aim of Program 10

Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.

โ† All Programs
Solution

Aim:

☛   Write a Ruby program to retrieve the total marks where subject name and marks of a student stored in a hash.

Solution :

PROGRAM: (total_marks.rb)

 
student_marks = {
  "Maths" => 85,
  "Science" => 92,
  "English" => 78,
  "Hindi" => 88,
  "Telegu"=> 90
}

total_marks = 0

student_marks.each do |subject, marks|
  total_marks += marks
end

puts "Total Marks: #{total_marks}"



OUTPUT:

 
Total Marks: 433



โ† Back to Scripting Languages Lab Programs ๐Ÿ“š All Lab Manuals