starting_tickets = 20
tickets_sold = 10
message = "We started with " + str(starting_tickets) + " and have " + str(starting_tickets - tickets_sold) + " tickets left!"
print(message)
If you run the starting program below, you will get an error because you can't directly add numbers to strings. Use the str() function to convert integer variables to strings so the message will print correctly.
The following example demonstrates the expected program output.
We started with 20 and have 10 tickets left!
3 answers
numTickets = 20
soldTickets = 10
ticketsLeft = numTickets - soldTickets
print("We started with "+ numTickets + " and have " + ticketsLeft + " tickets left!" )
soldTickets = 10
ticketsLeft = numTickets - soldTickets
print("We started with "+ numTickets + " and have " + ticketsLeft + " tickets left!" )
numTickets = 20
soldTickets = 10
ticketsLeft = numTickets - soldTickets
print("We started with "+ str(numTickets) + " and have " + str(ticketsLeft) + " tickets left!" )
soldTickets = 10
ticketsLeft = numTickets - soldTickets
print("We started with "+ str(numTickets) + " and have " + str(ticketsLeft) + " tickets left!" )