Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Grouping with Parentheses Pares of a muthematical expression may he groyped with parentheses ro force some operatime to le performed befare athery, In the following,

image text in transcribed

Grouping with Parentheses Pares of a muthematical expression may he groyped with parentheses ro force some operatime to le performed befare athery, In the following, slatement, the variables a and bare aslded togetber, and their sum is divided by 4 : resu7t-(a+b);4 75 of 886 and their values In the Spotlight: Calculating an Average Derermining rhe awerage of a group of salues is a simple calcularion: add all of rhe salues then divide the sam by the namber of values, Although this as a straightionward calculation, it is eary to make a mistake when writing a pregeam that talkalates an average, For easmple, ket's assume that the variables 80,b, and e each beld a value and we want to calculate the average of those values. If we are careless, we might write a statement such as the following to pertorm the calculation: sverage =a+b+ci3.0 Can you see the troo in this staternent? When it executes, the division will talo place first. The value in e will be divided by 3 , then the result will be added to a+b. That is aoc the correst way to czlculate an average. To coerect this errar, pe need to put parentbeses around a+b+a, as shown bere: average={a+b+a};3.0 2.7 Perferming Cakulations Ler's step through the process of writing a program that calculates an average. Suppase you have raken three tests in your computer sience class, and you want to write a program that will display the average of the test acores. Here is the algorithm; 1. Cer the first lest seope. 2. Gers she socond rest secte. 3. Get hev shnd cest score: 4. Cakculare the mernge by adding the chree keat scores and dividng the swem by 3 . 5. Display the aurnnge. In steps 1,2 , and 3 we will prompt the user to enter the three test sceres. Wie will store those test scores in the variables test1, test2, and test3. In step 4, we will calculate the average of the three test seares, We will ase the following statement ro perform the calculation and stare the result in the avarage variable: average=(test1+tas2+test3);3.0 Last, in step 5 , we display the avenage. Program 2-16 shows the program. Pregram 2-16 \{test_score_average.py\} A Get three tost scores and assign then to the * test^, test2, and test? variables. test1 = floatifinput ' Enter the first test score: 'j) test2 = float(inputi'Enter the seoond tast seore: 'i) testa = floutinnoti' Enter the third tast score: 'j) A Caiculate the average of the thrse boares A swe assign the rosult to the average variable. average = (test1 - test 2+ test 3 ), 3.0 * Cisplay the average. print! 'The average score is', averagel Program Dutput (with input shawn in bold) Enter the pirat teat beore: 90 Eithe Enter the secend test acere: 80 Erter] Enter the third test score: 100 cotur The average scare is 90.0 The Exponent Operator Two asterisks written together (") is the exponent operator, and its purpose is to raise a number to a power. Far example, the following statement raises the length wariable to the power of 2 and assigns the resalt to the area pariable: area=length=+2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

2. What is the meaning and definition of Banking?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago