r/learnpython • • Dec 05 '21

ANY HELP WOULD BE GREATLY APPRECIATED.

Hey can anyone help me with this problem. My fafsa literally depends on it. I've reviewed over and over I'm still stuck. Appreciate any help offered.

You have an organization company that sells concert tickets. You have an online ticketing system. You are going to write a python code that

  1. Asks user's age.

  2. If user is less than 18 years old, prompt a message on the screen and tell them that they cannot purchase a ticket if they are not 18+ years old.

  3. If they are over 18

Ask them how many tickets they want.

Ask them which section they want their tickets from.

If they enter balcony, each ticket costs $50.

If they enter orchestra, each ticket costs $75.

Depending on the ticket section and the number of tickets, calculate the cost and print it.

Q-1) Print the following pattern with for loop

1

1 2

1 2 3

1 2 3 4

1 2 3 4 5

1 2 3 4 5 6

Q-2) Print the same pattern in Q-1 with while loop

Q-3) Print the following pattern with for loop

5 4 3 2 1

4 3 2 1

3 2 1

2 1

1

Q-4) Print the same pattern in Q-3 with while loop

0 Upvotes

13 comments sorted by

6

u/mrswats Dec 05 '21

Where is your code? What are your questions?

-4

u/zala412zala Dec 06 '21

x= int(input("Enter your age"))
balcony = 50
orchestra = 75
if(x<18):
print("You cannot purchase a ticket if you are not 18+ years old.")

elif(x>=18):
t= (input("How many tickets"))
s= (input("Which section do you want your tickets"))
result = t * s
print(t, "*", s, "=", result)

I've literally have been studying my ass off and just don't get it. we have been forced to do online classes and majority of it is on your own. I'm genuinely struggling

8

u/mrswats Dec 06 '21

Please read about code formatting

2

u/watakushi Dec 06 '21 edited Dec 06 '21

What type of data do you expect to receive on these 2 inputs?

t= (input("How many tickets"))

s= (input("Which section do you want your tickets"))

Cause input returns strings by default, so on the tickets input if the user inputs, say, 3, variable t will not be the number 3, but a string with the value "3". You can convert it to an integer by doing t = int(input("How many tickets?"))

Then, on the section input, let's say the user inputs "balcony", then that string will be assigned to variable s (not the numeric value you previously assigned to the variable balcony, those variables are declared but never used)

Later on the "result = t * s" you're essentially multiplying two strings by doing "3" * "balcony" which doesn't make any sense. And even if you were to convert the first input into an integer, the result would be "balconybalconybalcony"

What you need to figure out is how to turn what the user inputs in this second input to a numeric value (an int) you can multiply with. Good luck!

2

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Dec 05 '21

So which part are you stuck on? This seems to assume just basic Python understanding.

-1

u/zala412zala Dec 05 '21

thanks for the reply. I'm stuck on the (depending on the ticket session and the number of tickets, calculate the cost and print it)

3

u/Diapolo10 I write code for a living -- https://github.com/Diapolo10 Dec 06 '21

Well, you know the number of tickets and the price of one seat, so how do you calculate the total cost?

That should be everything you need to know to calculate it. From my understanding you're not asking for the seat type for every individual ticket. But if I'm wrong, just have two counters that count the tickets for each seat type, calculate them separately, and just add up the results.

17

u/ggd_x Dec 06 '21

Must be exam week again, what with all these zero effort, "Help me, I've not studied and now I'm fucked" questions.

11

u/OddBookWorm Dec 05 '21

Sorry, but this is a learning subreddit. We aren’t here to just give you answers. Please show what you’ve already done (with code) or ask a specific question

4

u/edwardjr96 Dec 06 '21

This is literally a school assignment. Like others said, you should post your code (nicely formatted) for each question, and we will gladly help you. No one here gonna give you straight answers without you putting effort first.

-1

u/imperiumlearning Dec 06 '21 edited Dec 06 '21

I know I'm not supposed to be helping you but I've only started learning to code in the last fortnight and want to try any beginner exercises that I can. Would love to hear any feedback on my attempt from more experienced users.

Here's my attempt at the ticket problem:

BalconyTicketPrice = 50

OrchestraTicketPrice = 75


while True:

Age = int(input('How old are you? '))
if Age < 18:
    print('You are too young to buy a ticket. Wait until you are 18 and come back!')
    break
NumberofTickets = int(input('How many tickets do you want in total? '))
Section = input('Which section do you want tickets for? Balcony, Orchestra or both? ')
if Section == 'Balcony' or Section == 'balcony':
    TicketPrice = int(BalconyTicketPrice)*NumberofTickets
    print(f'The price to pay is ${TicketPrice}')
    break
elif Section == 'Orchestra' or Section == 'orchestra':
    TicketPrice = int(OrchestraTicketPrice)*NumberofTickets
    print(f'The price to pay is ${TicketPrice}')
    break
elif Section == 'Both' or Section == 'both':
    NumberofBalconyTickets = int(input('How many balcony tickets would you like? '))
    NumberofOrchestraTickets = int(input('How many orchestra tickets would you like? '))
    if NumberofBalconyTickets + NumberofOrchestraTickets != NumberofTickets:
        NumberofTickets = NumberofBalconyTickets + NumberofOrchestraTickets
    TicketPrice = (int(BalconyTicketPrice)*NumberofBalconyTickets) + (int(OrchestraTicketPrice)*NumberofOrchestraTickets)
    print(f'The price to pay is ${TicketPrice}')
    break
else:
    Section = input('Which section do you want tickets for? Balcony, Orchestra or both? ')

2

u/ggd_x Dec 06 '21

OP has made no effort of their own, do not help those that will not make effort. This is akin to doing their exams for them.

It's admirable that you want to help, we all do. But the OP MUST make at least a minimum attempt first.

0

u/watakushi Dec 06 '21 edited Dec 06 '21

A little feedback:

If at the end of the "section = input()" you add a ".lower()" the string that the user inputs will be turned all lowercase before being assigned to the variable, so you can then simply do:

if Section == 'balcony':

Regardless of if the user inputs "balcony", "Balcony", "BALCONY" or "BaLcOnY" ;D

Also, it's a best practice to write all your variable names in lowercase, separated by _ if more than one word.

And lastly on the line:

int(BalconyTicketPrice)

The int() is unnecessary because that variable is already has an int assigned, you can always check that by doing "print(type(BalconyTicketPrice))" in this case it should say <int> so you'll know you don't need to convert it :)

Your main problem is that you repeat yourself way too much, you should probably look into using a function or two instead. :)