+ 4
Please help me with my code 👨💻
13 Antworten
+ 11
Sakshi
if you are going to run the code in code coach, some minimum modifications has to be made:
> input has to be done by using input() function and split to a list of strings. currently it uses *hard coded* input text
> in the for loop an alternative clause (else...) is missing for orders that are not offered (read the task description)
> the final output has to be *rounded up* using ceil() function
+ 7
Sakshi , Esseoghene Orovwigho ,
these lines of code are not required, since the variables are never used. they do not affect the execution of the code, but should be removed for clarity:
...
Pizza = 6
Nachos = 6
Cheeseburger = 10
Water = 4
Coke = 5
...
+ 3
https://code.sololearn.com/cOcdR02wL3ye/?ref=app
Here is the corrected code, please check your mistake and then correct it.
+ 2
Esseoghene Orovwigho
your code is:-
orders = str(Pizza,Cheeseburger,Water,Popcorn)
total = 0
Pizza = 6
Nachos = 6
Cheeseburger = 10
Water = 4
Coke = 5
snacks = [Pizza,Nachos,Cheeseburger,Water,Coke]
for x in orders:
if snacks != orders:
return(snacks.replace(coke))
total += orders
tax = total*0.07
print(total + tax)
Sorry for the inconvenience, I am also don't know too much python, somebody will help you surely but you post code this, before you talk about replace (coke).
+ 2
Sakshi Thank you so much🙏🏾🙏🏾
+ 1
Lothar Actually bro, you are right but I don't read the task because he can do yourself, I just try to correct the code what he mention that's it. I think you understand it what I mean to say.
+ 1
Sakshi you didnt replace the “popcorn” in orders to “coke” as written in the description
+ 1
Esseoghene Orovwigho
orders = input().split()
Pizza = 6
Nachos = 6
Cheeseburger = 10
Water = 4
Coke = 5
total = 0
for order in orders:
if order == 'Nachos' or order == 'Pizza':
total += 6
elif order == 'Cheeseburger':
total += 10
elif order == 'Water':
total += 4
else:
total += 5
tax = total * 0.07
total_with_tax = total + tax
print("{:.2f}".format(total_with_tax))
See the code this is generated by chatgpt.
+ 1
Lothar ok bro
0
I’m still confused
Could someone just rewrite the code for me
0
Esseoghene Orovwigho welcome 😊
0
Lothar I think it's required bro because this is the task of code coach, yesterday I also do this task in Java.If we put pizza, Nachos, Cheeseburger, and water then the print total taxes.
Because the task is this:-
You and three friends go to a baseball game and you offer to go to the concession stand for everyone. They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. Water is $4.00 and Coke is $5.00. Tax is 7%.
Task
Determine the total cost of ordering four items from the concession stand. If one of your friend’s orders something that isn't on the menu, you will order a Coke for them instead.
Input Format
You are given a string of the four items that you've been asked to order that are separated by spaces.
Output Format
You will output a number of the total cost of the food and drinks.
Sample Input
'Pizza Cheeseburger Water Popcorn'
Sample Output
26.75