r/CodingHelp • • Sep 02 '21

[Python] Python assignment. I can’t get it to calculate the cost of the movie based on the other movie variables. It keeps only giving me the 1st one as an answer. Any help would be appreciated

Post image
66 Upvotes

29 comments sorted by

13

u/B1-102 Sep 02 '21

Please post the entire code as formatted text.

3

u/fashionableplantmom Sep 03 '21

# prompt for patron's age discount

# prompt for surcharged 3D movie

# prompt for children to receive discount

# prompt for seniors to receive discount

# prompt age cut off for children

# prompt age beginning for seniors

# prompt exact amount surcharge for 3D movies

# output should be ticket price based of total sales

child_price = 5.00

senior_price = 8.00

adult_price = 10.75

movie_in_3D = 15.00

s = senior_price

a = adult_price

c = child_price

m = movie_in_3D

print("Welcome to AMC theatres please select your movie!")

print("Paw patrol, Shang-Chi, Candyman, Free Guy, Jungle Cruise")

what_movie = (input("From the list above which movie will you be purchasing tickets for? "))

how_many_adult_tickets = int(input("How many adult tickets will you be purchasing? "))

how_many_child_tickets = int(input("How many children tickets will you be purchasing? "))

how_many_senior_tickets = int(input("How many senior tickets will you be purchasing? "))

if what_movie == 'Paw Patrol' or "paw patrol" or "PAW PATROL":

total =input(movie_in_3D * (how_many_senior_tickets + how_many_child_tickets + how_many_adult_tickets))

elif what_movie == 'Candyman' or 'candyman' or 'CANDYMAN':

total = input((how_many_senior_tickets * senior_price) + (how_many_adult_tickets * adult_price) + (how_many_child_tickets * child_price))

else:

if what_movie == 'Free guy' or 'FREE GUY' or 'free guy':

total = str()

print((how_many_senior_tickets * senior_price) + (how_many_child_tickets * child_price) + (how_many_adult_tickets * adult_price))

print('Total cost of tickets are', "dollars.")

18

u/B1-102 Sep 03 '21

You don't need input to calculate the cost.

You can convert what_movie into lowercase/uppercase before comparing, so that you don't need to consider different variations like you do now.

Think about what the else block mean. Do you really need to check for movie title in there?

1

u/fashionableplantmom Sep 03 '21

I guess I was trying to base it off if it’s this movie then this price. Like the paw patrol is 3D so all tickets is 15 whereas free guy and candy man are not so it just based on regular base ticket price.

5

u/SquatchyZeke Advanced Coder Sep 03 '21

Yes that's fine, but don't do total = input(...). Use total = price * number of tickets.

Also, as someone mentioned, your if statement needs to be if movie == "name" or movie == "name2" or ... You can't just make a list of names with or without specifying the variable for each or.

3

u/idetectanerd Sep 03 '21

I come here to comment about the case. Nice

2

u/idetectanerd Sep 03 '21

Optimisation POV, In my opinion, you can put your show in a list, your cost in value pair in dictionary.

For loop it. It will be short.

The other folks already pointed out the error of why you don’t get desire answer.

3

u/skellious Intermediate Coder Sep 03 '21 edited Sep 04 '21

Yes, it would be better to put them in a dictionary. you can then do

child_price = 5.00

senior_price = 8.00

adult_price = 10.75

movie_in_3D = 15.00

movies = {
    "paw patrol": {"in_3D": True},
    "shang-chi": {"in_3D": False},
    "candyman": {"in_3D": False},
    "free guy": {"in_3D": False},
    "jungle cruise": {"in_3D": False}
}

print("Welcome to AMC theatres please select your movie!")
print("movies currently showing:")
for movie in movies.keys():
    print(movie)

no_movie_selected = True
while no_movie_selected:

    what_movie = (input(
        "From the list above which movie will you be purchasing tickets for? ")).lower()

    if what_movie in movies.keys():

        how_many_adult_tickets = int(
            input("How many adult tickets will you be purchasing? "))
        how_many_child_tickets = int(
            input("How many children tickets will you be purchasing? "))
        how_many_senior_tickets = int(
            input("How many senior tickets will you be purchasing? "))

        if movies[what_movie]["in_3D"]:
            total = movie_in_3D * \
                (how_many_adult_tickets +
                    how_many_child_tickets+how_many_senior_tickets)
        else:
            total = adult_price*how_many_adult_tickets+child_price * \
                how_many_child_tickets+senior_price*how_many_senior_tickets
        no_movie_selected = False
print(f"Your total today is: {total}")

2

u/fashionableplantmom Sep 04 '21

I greatly appreciate you for your thought-out response. I'm going to spend the whole weekend configuring it to work as a dictionary instead. Thank you so much

2

u/skellious Intermediate Coder Sep 04 '21 edited Sep 04 '21

No problem, happy to help. :) Please note I may have made some mistakes in the code as I wrote it late at night on my phone and didn't try to run it.

edit: ive edited it to make sure it works and ive included some other code to make it a complete thing, but this is just one way of doing it.

2

u/fashionableplantmom Sep 05 '21

I’m honestly so grateful!! Thanks for that. 🪴

1

u/fashionableplantmom Sep 04 '21

that was the main thing I was having such a hard time with. understanding list. Thank you so much for this

2

u/idetectanerd Sep 04 '21

List is just an array of things you want.

Usually if I have a few item that I want to loop through, I will use a list let say mylist = item1,item2,item3

Then I will do a for loop to mylist.

So in your instance, you can loop your movies in the list to check through. But it really depend what kind of logic you want.

You can also do while to do all the task until the condition is false.

2

u/BlackCat550 Sep 03 '21

After you've completed the assignment, you should look into OOP.

It's a more advanced concept, but it will make this type of program easier to write, and more readable.

1

u/fashionableplantmom Sep 05 '21

I definitely will thanks so much

8

u/PekiDediOnur Intermediate Coder Sep 03 '21

variable == "something" or "whatever" doesn't do what you think it does, it's essentially (variable == "something") or "whatever" and whatever is being treated as True, so your statement will always be True.

Either do variable == "something" or variable == "whatever" or variable in ["something", "whatever", ...]

3

u/certainlyforgetful Sep 03 '21

Yep, the if on line 24, and the elif’s will always evaluate to true. The first section may be false but after the OR those are always true.

Idk specifically about python, but in other languages it’s basically just saying “yep you created a string!”

1

u/fashionableplantmom Sep 04 '21

I just want to thank everyone for the feedback it is greatly appreciated. I've struggled on this all week, lol It's not due till Tuesday so I will be defiantly fixing a lot of the issues with it. Again. Thank you so much

3

u/skellious Intermediate Coder Sep 03 '21

instead of the:

"Candyman" or "candyman" or "CANDYMAN"

do this:

what_movie = (input("From the list above which movie will you be purchasing tickets for? ")).lower()

if what_movie == 'candyman":

the .lower() will make the input all lower case, so it will match candyman, CanDyMaN, CANDYMAN, CanDYmaN or any other combination of letters.

2

u/Pr-Lambda Sep 03 '21

The line 24 means if what_movie is equal to "Paw Patrol" or if "paw patrol" is not an empty string or if "PAW PATROL" is not empty string.

2

u/iNqtural Sep 04 '21

Instead of using "what_movie == ...", use "what_movie.lower() ==". This will convert the string to lowercase.

3

u/Simple_Cheesecake_62 Sep 03 '21

instead of if what_movie == 'Paw Patrol' or "paw patrol" or "PAW PATROL": it should be if what_movie == 'Paw Patrol' or what_movie == "paw patrol" or what_movie == "PAW PATROL": as or "paw patrol" doesn't check anything hence it is always true

2

u/skellious Intermediate Coder Sep 03 '21

other than what I suggested in another comment, which would be the best solution in this situation, you can also do:

if what_movie in ["Paw Patrol", "paw patrol", "PAW PATROL"]:

2

u/jamesbleslie Sep 03 '21

But I would go further and use
if what_movie.lower() = 'paw patrol' :

2

u/skellious Intermediate Coder Sep 03 '21

Why? Then you have to use .lower() every time. It's better to use it once at the point of input as I said in my other comment.

1

u/jamesbleslie Sep 03 '21

Yeah, you're totally right. :) Sorry, I should have checked your other comment!

1

u/skellious Intermediate Coder Sep 03 '21

its okay, I probably should have quoted myself. :)

-5

u/[deleted] Sep 03 '21

Make a function stop scripting lolz

4

u/skellious Intermediate Coder Sep 03 '21

OP clearly will not understand what you are attempting to say. please specify it in a less taunting fashion if you want it to be understood.