Engineering : asked on ag1606
 23.04.2022

What is 2.4 code practice question 2 edhesive

. 18

Step-by-step answer

17.02.2022, solved by verified expert

Faq

Computers and Technology
Step-by-step answer
P Answered by Master

import math

num=int(input("Enter a number: "))

x=math.fabs(num)

y=math.sqrt(x)

print(y)

Explanation: It will get the square root, then it will get the absolute value of the square root.

Computers and Technology
Step-by-step answer
P Answered by PhD

num = float(input("Enter a number : "))

ab = abs(num)

sqrt = float(ab ** 0.5)

print(sqrt)

Explanation:

Computers and Technology
Step-by-step answer
P Answered by Specialist

Explanation:

Let's code it using python. We can take care of the negative number by placing an absolute function at the end. Basically the decimal part is calculated by subtracting the integer part from the original input number

def decimal_print(number):

    int_part = int(number)

    decimal_part = number - int_part

    return abs(decimal_part)

Computers and Technology
Step-by-step answer
P Answered by PhD

Following are the C++ program to calculate the decimal part:

Program Explanation:

Defining the header file. Defining the main method. Inside the method, a float variable "num" is declared that inputs the value. In the next step, an integer variable "x" is declared that converts float value into an integer that holds the whole part number.In the next step, "num" is declared that removes the whole number part from the decimal value, and prints its value.

Program:

#include <iostream>//header file

using namespace std;

int main()//main method  

{

float num;//defining a string variable

cout<<"Enter password: ";//print message

cin>>num;//input float value

int x=int(num);//defining integer variable that converts float value into integer that hold whole part number

num=num-x;//remove whole number part from the decimal value  

cout<<num;//print decimal number

  return 0;

}

Output:

Please find the attached file.

Learn more:

link

Computers and Technology
Step-by-step answer
P Answered by PhD

Following are the C++ program to calculate the decimal part:

Program Explanation:

Defining the header file. Defining the main method. Inside the method, a float variable "num" is declared that inputs the value. In the next step, an integer variable "x" is declared that converts float value into an integer that holds the whole part number.In the next step, "num" is declared that removes the whole number part from the decimal value, and prints its value.

Program:

#include <iostream>//header file

using namespace std;

int main()//main method  

{

float num;//defining a string variable

cout<<"Enter password: ";//print message

cin>>num;//input float value

int x=int(num);//defining integer variable that converts float value into integer that hold whole part number

num=num-x;//remove whole number part from the decimal value  

cout<<num;//print decimal number

  return 0;

}

Output:

Please find the attached file.

Learn more:

link

Computers and Technology
Step-by-step answer
P Answered by PhD

The code is in Java.

It calculates the decimal portion of a number by subtracting the integer portion from the number. It also uses if structure to check if the number is a negative one.

Comments are used to explain each line of code.

//Main.java

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 //Initialize the Scanner object to be able to get input

 Scanner input = new Scanner(System.in);

 

 //Declare the variables

 double number, decimalPortion;

 

 //Ask the user to enter a number

 System.out.print("Enter a number: ");

 number = input.nextDouble();

 

 //Get the decimal portion of the number by subtracting the integer part from the number

 decimalPortion = number - (int) number;

 

 //If the number is negative one, multiply the decimal portion with -1 to convert it to a positive value

 if(number < 0)

     decimalPortion *= -1;

 

 //Print the decimal portion

 System.out.println(decimalPortion);

 

}

}

You may see a similar question in the following link:

link

Computers and Technology
Step-by-step answer
P Answered by Specialist

Explanation:

Let's code it using python. We can take care of the negative number by placing an absolute function at the end. Basically the decimal part is calculated by subtracting the integer part from the original input number

def decimal_print(number):

    int_part = int(number)

    decimal_part = number - int_part

    return abs(decimal_part)

Computers and Technology
Step-by-step answer
P Answered by PhD

The program is an illustration of conditional statements.

Conditional statements are statements whose execution is dependent on its truth value.

The program in Python, where comments are used to explain each line is as follows:

#This initializes the dictionary

dict = {"a": 4, "b": 3, "c": 2, "d": 1, "f": 0}

#This gets input for grade

grade = input().lower()

#This gets input for the weighted average

weighted = int(input())

#If the weighted average is 1, and the grade is in the dictionary

if weighted == 1 and grade in dictionary:

   #This prints the GPA score

   print("Your GPA score is: "+str(dict[grade] + 1))

#If the weighted average is 0, and the grade is in the dictionary

elif weighted == 0 and grade in dictionary:

   #This prints the GPA score

   print("Your GPA score is : "+str(dict[grade]))

#Otherwise

else:

   #The grade is invalid

   print("Invalid")

Read more about similar programs at:

link

Try asking the Studen AI a question.

It will provide an instant answer!

FREE