Help with the Ballpark problem in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help with the Ballpark problem in Python

I'm trying to get Python to index the user input, then to assign a price to each input and create a sum total. Then to finally print the total with an applied tax. Input: Four food items separated by spaces. If an item is not on the menu, order a coke instead. Output: total price with 7% tax input_string = input() userOrders = input_string.split() total = 0 if userOrders.index(Nachos): total += 6 elif userOrders.index(Pizza): total += 6 elif userOrders.index(Cheeseburger): total += 1 elif userOrders.index(Water): total += 4 elif userOrders.index(Coke): total += 5 print(int(total*0.93))

5th Jan 2020, 7:47 PM
Ilya Khleboyko
Ilya Khleboyko - avatar
3 Answers
+ 1
You have to write 'Nachos' etc. instead of Nachos. You haven't solved the part where people order something that's not on the list. You are subtracting taxes, but you should be adding them. Price of Cheeseburger isn't right.
5th Jan 2020, 8:06 PM
HonFu
HonFu - avatar
0
Yes, with all of those fixes, I still get a traceback error to the userOrders.index(Nachos): line.
5th Jan 2020, 8:37 PM
Ilya Khleboyko
Ilya Khleboyko - avatar
0
Complete the code below by reordering the remaining code to find three subgroups of wines based on measurements on alcohol and total_phenols using k-means. X = wine[['alcohol', 'total_phenols']] scale = StandardScaler() scale.fit(X) X_scaled = scale.transform(X) kmeans = KMeans(n_clusters=3) kmeans.fit(X_scaled)
21st Nov 2020, 5:19 AM
Jason Chew
Jason Chew - avatar