1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kow [346]
3 years ago
15

Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targe

tValue. Otherwise, print "Not equal".
Computers and Technology
2 answers:
Likurg_2 [28]3 years ago
3 0

Answer:

The program to this question as follows:

Program:

targetValue = 0.3333 #defining variable targetValue and assign value

sensorReading = 0.0 #defining variable sensorReading and assign value

sensorReading = 1.0/3.0 #calculate value in sensorReading variable

Val=sensorReading - targetValue

#calculate the difference and store in Val variable

if (Val < 0.0001): #use of if block to check condition

  print ("Equal")  #print value

else:  #else block

  print ("Not equal") #print value

Output:

Equal

Explanation:

In the above Python program code, there are two variables "targetValue and sensorReading" is defined, in which targetValue store a value, that is "0.3333", and sensorReading holds a value, that is "0.0".

  • In the next step, the "Val" variable is defined, that calculate the difference between both variable, that conditional statement is used.
  • In if block, if the value is less then "0.0001", it will print value "Equal", otherwise, it will go to the else block, that will print "Not equal".
Anna11 [10]3 years ago
3 0

Full Question

Write an expression that will cause the following code to print "Equal" if the value of sensorReading is "close enough" to targetValue. Otherwise, print "Not equal". Ex: If targetValue is 0.3333 and sensorReading is (1.0/3.0), output is: Equal

#include <iostream>

#include <cmath>

using namespace std;

int main() {

double targetValue;

double sensorReading;

cin >> targetValue;

cin >> sensorReading;

if (/* Your solution goes here */) {

cout << "Equal" << endl;

} else {

cout << "Not equal" << endl;

} return 0;

}

Answer:

if (abs(targetValue - sensorReading) <= 0.0001)

Explanation:

Replace

if (/* Your solution goes here */) {

With

if (abs(targetValue - sensorReading) <= 0.0001)

Two values are considered to be close enough if the difference between the values is 0.0001

Splitting the codes into bits;

abs

targetValue - sensorReading

<=

0.0001

The keyword abs is to return the absolute value of the expression in bracket.

This is needed because the expression in the bracket is expected to return a positive value.

To do this the absolute keyword is required.

targetValue - sensorReading returns the difference between the variables

<= compares if the difference falls within range that should be considered to be close enough

0.0001 is the expected range

You might be interested in
Lamp is an acronym for a complete solution of open source software that goes together to build a general purpose web server. whi
Westkost [7]
Answer choices?

LAMP contains <span>Linux, Apache, MySQL, and PHP.</span>
3 0
3 years ago
I have no idea what I’m doing but this is for a class grade and also on Replit<br><br> Please Help!!
Tatiana [17]

Answer:

I've compiled some code below to help you out ;)

Explanation:

# Program make a simple calculator

# This function adds two numbers

def add(x, y):

   return x + y

# This function subtracts two numbers

def subtract(x, y):

   return x - y

# This function multiplies two numbers

def multiply(x, y):

   return x * y

# This function divides two numbers

def divide(x, y):

   return x / y

print("Select operation.")

print("1.Add")

print("2.Subtract")

print("3.Multiply")

print("4.Divide")

while True:

   # take input from the user

   choice = input("Enter choice(1/2/3/4): ")

   # check if choice is one of the four options

   if choice in ('1', '2', '3', '4'):

       num1 = float(input("Enter first number: "))

       num2 = float(input("Enter second number: "))

       if choice == '1':

           print(num1, "+", num2, "=", add(num1, num2))

       elif choice == '2':

           print(num1, "-", num2, "=", subtract(num1, num2))

       elif choice == '3':

           print(num1, "*", num2, "=", multiply(num1, num2))

       elif choice == '4':

           print(num1, "/", num2, "=", divide(num1, num2))

       

       # check if user wants another calculation

       # break the while loop if answer is no

       next_calculation = input("Let's do next calculation? (yes/no): ")

       if next_calculation == "no":

         break

   

   else:

       print("Invalid Input")

I got it from this link, https://www.programiz.com/python-programming/examples/calculator

3 0
2 years ago
"An Infrastructure as a Service provider shares its computing resources between a number of different clients, each of whom has
arlik [135]

Answer:

Elasticity

Explanation:

Cloud computing can be defined as a type of computing that requires shared computing resources such as cloud storage (data storage), servers, computer power, and software over the internet rather than local servers and hard drives.

Generally, cloud computing offers individuals and businesses a fast, effective and efficient way of providing services.

Cloud computing comprises of three (3) service models and these are;

1. Platform as a Service (PaaS).

2. Software as a Service (SaaS).

3. Infrastructure as a Service (IaaS).

An Infrastructure as a service (IaaS) provides virtualized computing resources for end users over the internet. For example, the provisioning of On-demand computing resources such as storage, network, virtual machines (VMs) etc., so as to enable the end users install various software applications or programs, database and servers.

Elasticity simply means that cloud computing gives an end user the ability to expand and reduce resources according to his or her specific service requirement because resources such as servers can be used to execute a particular task and after completion, these resources can then be released or reduced.

Hence, the Cloud computing concept which is illustrated in this scenario is elasticity

4 0
3 years ago
A taxi cab costs $1.25 for the first mile and $0.25 for each additional mile. Write an
Mumz [18]

Answer:

0.25x+1.25=8

Explanation:

Hope this helps

3 0
3 years ago
Help me please, I'm attempting a test<br>​
dusya [7]
It’s A it’s a keyboard
8 0
3 years ago
Read 2 more answers
Other questions:
  • As referenced in this Canvas guide (Links to an external site.), Canvas is best viewed at a minimum of 800x600 pixels, which is
    5·1 answer
  • Type of malware that is spread when you distribute
    12·1 answer
  • Write an application that accepts a word from a user and converts it to Pig Latin. If a word starts with a consonant, the Pig La
    8·1 answer
  • When you buy an Xbox 360 can you play online for free
    12·2 answers
  • Which statement accurately compares the restart at 1 and continue numbering featured of word
    15·2 answers
  • An alarm clock draws 0.5 A of current when connected to a 120 volt circuit. Calculate its resistance.
    10·1 answer
  • Kindly help me in this question by C PROGRAM or BY WORDINGS WHICH DESCRIBES THE PROBLEM SOLUTION
    6·1 answer
  • Based on what you know about the Sort and Find functions, return to the database file to determine the answers to the following
    7·2 answers
  • The __________ contains the basic elements of a user's program and can be generated directly from a compiled object file
    15·1 answer
  • Why should teachers refrain from using extreme language, such as “I’m dying of hunger,” around four- and five-year-old children?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!