Python: Creating dictionaries and functions -Create a dictionary named tickets_s
ID: 3825487 • Letter: P
Question
Python: Creating dictionaries and functions
-Create a dictionary named tickets_sold_dict.
-Write a loop which prompts the user to input the following keys and values and store them in tickets_sold_dict. Continue to read in the items while exit is not entered. Be sure to convert the number of tickets sold to an integer.
Smart Figures 1096
Guardians of the Universe 2400
Rogue Eight 958
exit
-Use the keys function to access the keys in tickets_sold_dict. Use a loop to print out the keys.
-Use the values function to access the values in tickets_sold_dict. Use a loop to print out the values.
-Compute the sum of all of the values for the tickets sold. Print out the sum.
-Create a dictionary named movie_tickets_dict and assign these values for the number of tickets sold.
Early Bird 511
Matinee 343
Evening 942
-Write a loop which allows the user to enter a key to search for in the movie_tickets_dict, if the key is in the dictionary, print out the number of tickets sold. If not print the the search key and " was not found".
-Write a function named total_sales_function that takes four parameters: a dictionary, the price of an early bird ticket, the price of a matinee ticket, and the price of an evening ticket. Create a dictionary tickets_dict. Use a loop to multiply the price of each type of ticket by the number of tickets sold. Store the key and the result of the calculation in the tickets_dict. Return the tickets_dict.
-Call the function from within main with the following arguments: movie_tickets_sold_dict, 4.00, 5.50, and 6.25. Assign the returned dictionary to tickets_cost_dict. Print out the keys and values with two decimal places of precision for each item of the returned dictionary tickets_cost_dict.
Explanation / Answer
import java.util.Map;
final class MyEntry<K, V> implements Map.Entry<K, V> {
private final K key;
private V value;
public MyEntry(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
V old = this.value;
this.value = value;
return old;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.