Home »
Ruby Tutorial »
Ruby Programs
Ruby program to find the division of students based on percentage using ternary operator
Last Updated : December 15, 2025
Problem Solution
In this program, we will read the percentage of the student from the user. Then we will find the division of students.
Program/Source Code
The source code to find the division of students based on percentage using the ternary operator is given below. The given program is compiled and executed successfully.
# Ruby program to find the division of students
# based on percentage using ternary operator
print "Enter percentage: ";
per = gets.chomp.to_f;
msg=per>=60 ? "FIRST" : per>=45 ? "SECOND" : per>=33 ? "THIRD" : "FAILED";
print "Division is: ",msg;
Output
Enter percentage: 72.4
Division is: FIRST
Explanation
In the above program, we read the percentage of the student from the user and found the division of students, and printed the appropriate message.
Ruby Basic Programs »
Advertisement
Advertisement