Example: Math and a Comment in Crystal
puts 12 - 4
puts 14.0 / 2.0
puts 15 > 5
puts 12 >= 12
puts 12 % 5 #modulus
Output:
8
7.0
true
true
2
Example: Combining a string and math with a placeholder
# Combining a string and math with a placeholder
puts "14.33 / 4.44 = #{14.33 / 4.44}"
Output:
14.33 / 4.44 = 3.227477477477477
Example: Fahrenheit to Celsius Conversation
f = 100;
c = (f - 32) * 5/9
puts "100 degrees Fahrenheit is #{c} Celsius."
Output:
100 degrees Fahrenheit is 37 Celsius.
Example: Multiple Variable AssignmentS
firstname, lastname, age = "John", "Smith", 45
print firstname, " is ", age, " years old."
Output:
John is 45 years old