Assign the value 13.9 to a variable named variable_a.Assign the value 2.8 to a variable named variable_b.Round variable_a using the round() command, and assign back the rounded value to variable_a.Convert variable_b from a float to an integer using the int() command, and assign back the converted value to variable_b.Display variable_a and variable_b using the print() command.
Question
Assign the value 13.9 to a variable named variable_a.Assign the value 2.8 to a variable named variable_b.Round variable_a using the round() command, and assign back the rounded value to variable_a.Convert variable_b from a float to an integer using the int() command, and assign back the converted value to variable_b.Display variable_a and variable_b using the print() command.
Solution
Here is the step by step process:
- Assign the value 13.9 to a variable named variable_a:
variable_a = 13.9
- Assign the value 2.8 to a variable named variable_b:
variable_b = 2.8
- Round variable_a using the round() command, and assign back the rounded value to variable_a:
variable_a = round(variable_a)
- Convert variable_b from a float to an integer using the int() command, and assign back the converted value to variable_b:
variable_b = int(variable_b)
- Display variable_a and variable_b using the print() command:
print(variable_a)
print(variable_b)
When you run this code, variable_a will display as 14 (since 13.9 rounds up) and variable_b will display as 2 (since the int() function truncates the decimal part).
Similar Questions
InstructionsAssign the integer 10 to a variable named variable_1.Assign the float 2.5 to a variable named variable_2.Update the value of variable_1 by adding the float 6.5 to its current value. You can use the += operator.Update the value of variable_2 by multiplying its current value by the integer 2. You can use the *= operator.Display variable_1 and variable_2 using print().
Complete the source code in order to print the float stored in the variable number with a precision of 2 digits.
To print out a and b given below, which of the following printf() statement will you use?float a=3.14:double b=3.14;
Daniel is working on a program for mathematical operations. Create a program that takes two floating-point numbers, multiplies them, converts the result to an integer, and based on the user's choice:If the choice is 1, add 5 to the converted integer.If the choice is 2, subtract 5 from the converted integer.If the choice is 3, divide the converted integer by 2.Display the original multiplication result as a float with two decimal places, and then show the modified integer after the chosen operation. Input format :The first line of input consists of two float values: num1 and num2 separated by a space.The second line of input consists of an integer value n, representing Daniels's choice:If the choice is 1, add 5 to the converted integer.If the choice is 2, subtract 5 from the converted integer.If the choice is 3, divide the converted integer by 2.Output format :The first line displays "Multiplication Result (as float): " followed by the result of multiplying num1 and num2 as a float value with two decimal values.The second line displays "Converted Integer: " followed by the result as an integer value after performing the required operation on the converted result based on the choice.
Problem Statement:Round off the given floating point value with accurate to 2 decimal places.Input Format:Accept a floating point valueOutput Format:Print the value accurate to 2 decimal placesConstraints:3.4E-4932 <= inp <= 1.1E+4932Sample Input 1:-165.12859Sample Output 1:-165.13Sample Input 2:12.53412Sample Output 2:12.53
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.