Ruby Basic Exercises: Check two temperatures
Ruby Basic: Exercise-25 with Solution
Write a Ruby program to check two temperatures and return true if one is less than 0 and the other is greater than 100.
Ruby Code:
def temp(temp1, temp2)
return ( temp1 < 0 && temp2 > 100 ) || ( temp1 > 100 && temp2 < 0 );
end
print temp(110, -1),"\n"
print temp(-1, 110),"\n"
print temp(2, 120)
Output:
true true false
Flowchart:
Ruby Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Ruby program to create a new string from a given string with the last character added at the front and back of the given string. The lenght of the given string must be 1 or more.
Next: Write a Ruby program to print 34 upto 41.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework