Mixed-up Code Questions

The following code should set the variable result equal to “x is less than 3” when x is less than 3. Otherwise, set it to “All done”. Be sure to indent correctly!

Write code that sets the variable result equal to “x is less than 3” when x is less than 3. Otherwise, set it to “All done”.

The following program should set the variable message to “Hello” if x is less than 2, “Hey” if x is greater than 2, and “Hi” if x is 2. Be sure to indent correctly and look out for extra code blocks!

Write code that sets the variable message to “Hello” if x is less than 2, “Hey” if x is greater than 2, and “Hi” if x is 2.

The following code should set price to 1.5 if weight is less than 2, otherwise set price to 1.3, then set total to the weight times price. For example, if weight is 0.5 then price should be set to 1.5 and total will be 0.75. Be sure to indent correctly!

Write code that sets price to 1.5 if weight is less than 2, otherwise set price to 1.3, then set total to the weight times price. For example, if weight is 0.5 then price should be set to 1.5 and total will be 0.75.

The following program should set the variable number to x is a number from 1 to 10 if the value of x is 1-10, x is a number less than 1 if the value of x is zero or below, and x is a number greater than 10 if the value of x is more than 10. Be sure to indent correctly and look out for extra code blocks!

Write code that sets the variable number to x is a number from 1 to 10 if the value of x is 1-10, x is a number less than 1 if the value of x is zero or below, and x is a number greater than 10 if the value of x is more than 10.

Arrange the code to calculate and print the cost of a 14 mile cab ride. If the distance traveled is less than or equal to 12 miles the cost is $2.00 a mile, and if the distance traveled is more than 12 miles the cost is $1.50 a mile. Be sure to indent correctly and look out for extra code blocks!

Write code that sets the variable rate to the cost of a 14 mile cab ride. If the distance traveled is less than or equal to 12 miles, then rate cost is $2.00 a mile, and if the distance traveled is more than 12 miles then rate cost is $1.50 a mile. Assign the final cost to the variable total.

Arrange the following code so that after x and y are defined, they are compared and if the value of x is less than y it sets the variable result to "x is less than y"; if x is greater than y then result is set to "x is greater than y"; and result is "x and y must be equal" if the values are equal. Be sure to indent correctly!

Write code so that after x and y are defined, they are compared and if the value of x is less than y it sets the variable result to "x is less than y"; if x is greater than y then result is set to "x is greater than y"; and result is "x and y must be equal" if the values are equal.

Arrange the following code so that after x and y are defined, they are compared and if the value of x and y are the same object then the variable value will be set to "x and y are the same"; if x and y have the same value then value will be "x and y have the same value"; and value is "x and y are not similar" if x and y do not fit the other conditionals. Be sure to indent correctly!

Write code so that after x and y are defined, they are compared and if the value of x and y are the same object the variable value will be set to "x and y are the same"; if x and y have the same value then value is "x and y have the same value"; and value is "x and y are not similar" if x and y do not fit the other conditionals.

Arrange the code to print the grade equivalent (string) for a score. It should return E for any value below 60, D for 61 to 69, C for 70 to 79, B for 80 to 89 and A for 90 and above.

Write code that will set the variable grade to the grade equivalent (string) for a score. It should set grade to E for any value below 60, D for 61 to 69, C for 70 to 79, B for 80 to 89 and A for 90 and above. For example, if the score is above 90, grade should be A.

The following program should set the variale result to determine whether a number is odd or even, but the lines are mixed up. Be sure to indent correctly and watch out for extra pieces of code!

Write code that should set the variable result to determine whether a number is odd or even.

The following program should set the variable result equal to “Good job” when the number is between 1 and 10 (inclusive) or is 15 and result should be set to “Fail” when it is not. Be sure to indent correctly and watch out for extra pieces of code!

Write code that should set the variable result equal to “Good job” when the number is between 1 and 10 (inclusive) or is 15 and result should be set to “Fail” when it is not.

You have attempted of activities on this page