Question

In: Computer Science

#Python Given a dictionary gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C":...

#Python

Given a dictionary

gradeCounts = { "A": 8, "D": 3, "B": 15, "F": 2, "C": 6 }

write the Python statement(s) to print:

a) all the keys.

b) all the values.

c) all the key and value pairs.

d) all of the key and value pairs in key order.

e) the average value.

f) a chart similar to the following in which each row contains a key followed by a number of asterisks equal to the key’s data value. The rows should be printed in key order, as shown below.

A: ********

B: ***************

C: ******

D: ***

F: **

Solutions

Expert Solution

Python code:

#initializing gradeCounts dictionary
gradeCounts={"A":8,"D":3,"B":15,"F":2,"C":6}
#a)printing all the keys
print(*gradeCounts.keys())
#b)all the values
print(*gradeCounts.values())
#c)all the key and value pairs.
print(*gradeCounts.items())
#d)looping all elements in key order
for i in sorted(gradeCounts):
#printing the pair
print((i,gradeCounts[i]),end=" ")
#printing a newline
print()
#e)printing average
print(sum(gradeCounts.values())/len(gradeCounts))
#f)looping all elements in key order
for i in sorted(gradeCounts):
#printing astricks for each key
print(i,": ","*"*gradeCounts[i])


Screenshot:


Input and Output:


Related Solutions

1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2...
1. Evaluate: (a+b)/(c-d) + 9/(a+d) when a=5, b=3, c=8, d=4 a. 6 b. 3 c. 15/2 d. 17/13 2. Solve for x: 5(x+3) = 35 a. 2 b. 7 c. 4 d. -4 3. Acid rain occurs primarily as a result of a. operating a nuclear power plant b. burning coal or oil containing sulfur c. by-products created by operating an oil refinery d. the use of Freon and other refrigerants 4. The "ozone holes" at the polar region arise...
A B C D E F 1 Chapter 8: Applying Excel 2 3 Data 4 Exhibit...
A B C D E F 1 Chapter 8: Applying Excel 2 3 Data 4 Exhibit 8-8: Standard Cost Card 5 Inputs Standard Quantity Standard Price 6 Direct materials 3.0 pounds $4.00 7 Direct labor 0.50 hours $22.00 per hour 8 Variable manufacturing overhead 0.50 hours $6.00 per hour 9 10 Actual results: 11     Actual output 2,090 units 12     Actual variable manufacturing overhead cost $6,174 13    Actual Quantity Actual price 14     Actual direct materials cost 6,115 pounds $3.9 pounds...
Given the following table of grades: Grades A B C D F Totals Males 17 8...
Given the following table of grades: Grades A B C D F Totals Males 17 8 14 11 3 53 Females 12 11 13 6 5 47 Totals 29 19 27 17 8 100 a. What is the probability that a randomly selected student got an A or B? b. What is the probability that if a student was female that they got a passing grade? c. What is the probability of a female student given that they got a...
Assume that: float a, b, c, d, f; and variables b, c, d, f are initialized....
Assume that: float a, b, c, d, f; and variables b, c, d, f are initialized. Write a line of c++ code that calculates the formula below and stores the result to the variable a:
Find the cubic equation. F(x)=ax^3+bx^2+cx+d F(-1)=3 F(1)=1 F(2)=6 F(3)=7 What is the value of a,b,c,d
Find the cubic equation. F(x)=ax^3+bx^2+cx+d F(-1)=3 F(1)=1 F(2)=6 F(3)=7 What is the value of a,b,c,d
Q1. a. Given a schema R (A, B, C, D, E, F) and a set F...
Q1. a. Given a schema R (A, B, C, D, E, F) and a set F of functional dependencies {A → B, A → D, CD → E, CD → F, C → F, C → E, BD → E}, find the closure of the set of functional dependencies ?+ b. Given a schema R = CSJDPQV and a set FDs of functional dependencies FDs = {C → CSJDPQV, SD → P, JP → C, J → S} 1. Find...
Given the vectors d = [−3, 6, 7] e = [8, −5, 3] and f =...
Given the vectors d = [−3, 6, 7] e = [8, −5, 3] and f = [3, −1, 4] a. Let x1(t) be the equation between d and f, express x1(t) in vector and parametric form. Then find x1(3); x1(-2); x1(1) b. Let x2(t) be the equation through f and parallel to x1(t), express x2(t) in vector and parametric form c. Let g = 4d – 2f, express the equation of the line containing g and e
A B C D E F 1 Chapter 3: Applying Excel 2 3 Enter a formula...
A B C D E F 1 Chapter 3: Applying Excel 2 3 Enter a formula into each of the cells marked with a ? below 4 Review Problem: Activity-Based Costing 5         6 Data 7     Deluxe Tourist 8 Annual sales in units 2,000 10,000 9 Direct materials per unit $25 $17 10 Direct labor-hours per unit 5 4 11 12 Direct labor rate $12 per DLH 13 14 Estimated 15 Overhead Expected Activity 16 Activities and Activity...
A B C D E F 1 Chapter 3: Applying Excel 2 3 Enter a formula...
A B C D E F 1 Chapter 3: Applying Excel 2 3 Enter a formula into each of the cells marked with a ? below 4 Review Problem: Activity-Based Costing 5         6 Data 7     Deluxe Tourist 8 Annual sales in units 2,000 10,000 9 Direct materials per unit $25 $17 10 Direct labor-hours per unit 5 4 11 12 Direct labor rate $12 per DLH 13 14 Estimated 15 Overhead Expected Activity 16 Activities and Activity...
(a) (f ∘ g)(3) (b) g(f(2)) (c) g(f(5)) (d) (f ∘ g)(−3) (e) (g ∘ f)(−1) (f) f(g(−1))
(a)    (f ∘ g)(3) (b)    g(f(2)) (c)    g(f(5)) (d)    (f ∘ g)(−3) (e)    (g ∘ f)(−1) (f)    f(g(−1))  
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT