Reputation: 1
Hi so I am a beginner in python and I am a little stuck on a problem I have for class and would like some guidance on this. The problem for class is:Stadium Seating: There are three seating categories at an athletic stadium. For a baseball game, Class A seats cost $15 each, Class B seats cost $12 each, and Class C seats cost $9 each. Create a python program that allows the user to enter the number of tickets sold for each class. The program should be able to display the amount of income generated from each class of ticket sales and the total revenue generated. Add input validation for number of tickets so that only numbers are allowed. Your program must not let the rest of the code run with invalid input.
now I got most of it to work but for some reason my income 2 and 3 are not multiplying the number of tickets for the price instead it's just writing the number of tickets that many times from the price.It seems to be only effecting the Class B and C
Here is my code
sales1=input("Enter number of tickets sold for Class A seats:")
#Validating sale
while not sales1.isnumeric():
print("INVALID INPUT:Please enter a number:")
#Convert sales to a number
sales1 =int(sales1)
sales2=input("Enter number of tickets sold for Class B seats:")
#Validating sale
while not sales2.isnumeric():
print("INVALID INPUT:Please enter a number:")
#Convert sales to a number
sales =int(sales2)
sales3=input("Enter number of tickets sold for Class C seats:")
#Validating sale
while not sales3.isnumeric():
print("INVALID INPUT:Please enter a number:")
#Convert sales to a number
Sales2 =int(sales3)
#Income
income1 = int(sales1 * 15)
print("Sales for Class A:$" , end="")
print(income1)
income2 = int(sales2 * 12)
print("Sales for Class B:$" , end="")
print(income2)
income3 = int(sales3 * 9)
print("Sales for Class C:$" , end="")
print(income3)
#Total
Total = int(income1 + income2 + income3)
print("Total revenue from ticket sales:$")
print (total)
my outcome just looks like this
Enter number of tickets sold for Class A seats:1 Enter number of tickets sold for Class B seats:1 Enter number of tickets sold for Class C seats:1 Sales for Class A:$15. Sales for Class B:$111111111111 Sales for Class C:$111111111
Upvotes: 0
Views: 2058
Reputation: 280973
sales =int(sales2)
Sales2 =int(sales3)
sales
and Sales2
are most likely not the variable names you wanted to use, considering you later do
income2 = int(sales2 * 12)
income3 = int(sales3 * 9)
as if sales2
and sales3
were integers. Most likely, you wanted to follow the pattern you set with sales1
:
sales1 =int(sales1)
and use
sales2 = int(sales2)
sales3 = int(sales3)
Note that once you have numbers, you don't need to keep calling int
on the result of every computation. This:
income1 = int(sales1 * 15)
can just be
income1 = sales1 * 15
While we're at it, here's your next bug. This part:
while not sales1.isnumeric():
print("INVALID INPUT:Please enter a number:")
asks the user to fix their input, but it doesn't actually let the user do so. It just prints an infinite stream of messages pestering the user to do it. You need to call input
to get a new number from the user. The same problem occurs with the other 3 input validation parts.
Upvotes: 4