Challenge: Formula Converter

Convert a mathematical formula into a program.

Note: We have revised this challenge based on the feedback from learners to make it more approachable.

Task

Write a program that calculates the result using the following formula:

result=3x+5y\text{result}= 3x +5y

Sample input

x = 3
y = 4

The resulting value

result = 29

Expected output

The calculated result is 29.

How to test your program

When you click the “Test” button of the code widget, you get two options:

  • Show Results: This shows the sample inputs and their respective results in comparison with the expected output. The actual output is the calculated result. The word “Succeeded” in the last column indicates that the calculated output matches the expected output. For example, if the values of x and y are 3 and 4 respectively, and the result is 29, then the last column shows “Succeeded.”

  • Show Console: This shows the output from the print() statements used in your code. You may use this to verify your calculations on the basis of sample test inputs. For example, if the values of x, and y are 3 and 4, respectively, then the output on the console should be The calculated result is 29.

Press + to interact
# You are required to write the code to convert the formula above to Ruby.
# Assume that we have x and y variables already defined:
# You are required to use the above variables to calculate
# the value of result
result = 0