#C14963. Convert Product Prices
Convert Product Prices
Convert Product Prices
You are given a list of product-price pairs, where each price is provided as a string. Your task is to convert the valid price strings into floating-point numbers and build a dictionary mapping each product name to its corresponding numeric price. If a price cannot be converted (for example, it contains non-numeric characters), skip that product.
The conversion can be mathematically described as follows: [ price = \text{float}(priceString) ] If the conversion fails, the product is omitted from the final dictionary.
Note: Prices can be zero or negative, and the order of products in the output should follow the natural ordering of keys (if applicable).
inputFormat
The input is given via standard input. The first line contains an integer ( n ) which denotes the number of products. Each of the following ( n ) lines contains two space-separated strings: the first is the product name and the second is the product price.
Example: 2 apple 0.5 orange 0.75
outputFormat
Output the dictionary representation (in a Python-style format) of the product-price pairs with valid prices. The keys should be the product names and the values their corresponding floating-point prices. If no product has a valid price, output {}.
Example: {'apple': 0.5, 'orange': 0.75}## sample
2
apple 0.5
orange 0.75
{'apple': 0.5, 'orange': 0.75}