BALLPARK TASK | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

BALLPARK TASK

What’s wrong with my code? x = input().split(" ") list = {"Pizza":6, "Cheeseburger":10, "Water":4, "Coke":5} sum = 0 for x in list: if x in list: sum += x else: sum += 5 tax = 7 res = sum + (sum / 100 * tax) print(res) Please, help me:)

2nd Jun 2023, 11:29 PM
Michael Ivanov
Michael Ivanov - avatar
2 Antworten
+ 3
Michael Ivanov 1. You used variable "x" for two distinct data: the input word list and the for loop 2. Variable "list" is a dictionary. The for loop as is iterates only on the keys. Since you need to compare keys and sum values, use "values" method, like: for product, price in x.keys(): 3. "list" is an existing class name. Change your variable name to avoid weird issues. Side hint: get used to meaningful variable and function names. They make your code more readable.
3rd Jun 2023, 12:36 AM
Emerson Prado
Emerson Prado - avatar
+ 1
I really appreciate your help, Emerson! I gonna try it :)
3rd Jun 2023, 12:54 AM
Michael Ivanov
Michael Ivanov - avatar