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

Scripting Languages - Lab Manual

Scripting Languages Laboratory โ€ข Program 8 Solution

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

Write a Ruby script to check two temperatures and return true if one is less than 0 and the other is greater than 100.

โ† All Programs
Solution

Aim:

☛   Write a Ruby program to check two temperatures and return true if one is less than 0 and the other is greater than 100.

Solution :

PROGRAM: (check_temperatures.rb)

 
def check_temps(temp1, temp2)
 return (temp1 < 0 && temp2 > 100) || (temp2 < 0 && temp1 > 100)
end

puts "Enter first temperature:"
temp1 = gets.to_i

puts "Enter second temperature:"
temp2 = gets.to_i

result = check_temps(temp1, temp2)
puts "Result: #{result}"


OUTPUT:

 
# Sample Run 1:
--------------
Enter first temperature:
110
Enter second temperature:
-2
Result: true

# Sample Run 2:
---------------
Enter first temperature:
-5
Enter second temperature:
120
Result: true

# Sample Run 3:
---------------
Enter first temperature:
34
Enter second temperature:
125
Result: false

# Sample Run 4:
---------------
Enter first temperature:
-10
Enter second temperature:
85
Result: false



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