Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMariel Vidal
11,056 PointsI'm getting invalid literal for int() with base 10: on this code
on this Code:
SERVICE_CHARGE = 2 TICKET_PRICE = 10 ticketsRemaining = 100
def calculatePrice(numberOfPeople): return (numberOfPeople*TICKET_PRICE)+SERVICE_CHARGE
while ticketsRemaining >=1: print("Tickets Remaining {}".format(ticketsRemaining))
userName = (input("What is your Name? "))
numberOfPeople = input("How many tickets would you like, {}? ".format(userName))
try:
numberOfPeople = int (numberOfPeople)
if numberOfPeople > ticketsRemaining:
raise ValueError ("There are only {} tickets remaining".format(ticketsRemaining))
except ValueError as err:
print("Oh No, That's not a valid input, {}.".format(err))
else:
amountDue= calculatePrice(numberOfPeople)
print("Total Cost ${}" .format(amountDue))
shouldProcced = input("Do you want to proceed ? (yes/no) ")
if shouldProcced.lower() == "yes":
print("SOLD!!")
ticketsRemaining = (ticketsRemaining - numberOfPeople)
else:
print("Thank You, {}".format(userName))
print("Sorry the tickets are all sold out")
1 Answer
boi
14,242 PointsThe error you are getting invalid literal for int() with base 10:
is because you are passing in a string
argument which can't be converted to an int
, also the message invalid literal for int() with base 10:
is the systems' way of handling this specific error, it might look that your code is incorrect or the error is weird but that is how the system handles this error.