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
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))  
Given a Boolean function: f(a,b,c,d) = m(1,6,7,10,12)+dc(3,4,9,15). i) Design a circuit for implementing f(a,b,c,d) with ONE...
Given a Boolean function: f(a,b,c,d) = m(1,6,7,10,12)+dc(3,4,9,15). i) Design a circuit for implementing f(a,b,c,d) with ONE 4-to-1 MUX and other basic logic gates. USE a and b as select inputs. ii) Draw the circuit. iii) Write the VHDL code for a 4-to-1 MUX, named “mux_4to1”, with input: a, b, c, d, s0, s1; and output: z. iv) Write the complete VHDL code for the above circuit in part (iii), named “Boolean_MUX”.
Given 8 cards: A, B, C, D, E, F, G, H How many ways can all...
Given 8 cards: A, B, C, D, E, F, G, H How many ways can all the cards be arranged if you select with replacement? How many ways can four cards be arranged if you select with replacement? How many permutations are possible if you select 5 cards without replacement? How many combinations are possible if you select 6 cards without replacement? If the B and C cards are made into A cards, and the E, F, and G cards...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT