Python

Solution - Basic Syntax

Ticket Machine

Our Solution

Here is our solution:

tickets = input("Enter number of tickets: ")
total_cost = int(tickets) * 11.99
print("The total cost of " + tickets + " tickets is $" + str(total_cost) + ".")    

Output:

Enter number of tickets: 7
The total cost of 7 tickets is $83.93.    

Note: The int() is used to convert from data from a string type to an integer type. This allows us to then perform math operations on the number.

The str() is used to change data from an integer or float type to a string data type. This basically converts the data to text that we can use in strings, print statements, etc. It removes any confusion concerning whether the code should add the value to something as a number, or attach it to the end of another piece of text (i.e. string).

If you don’t understand something, feel free to ask us on our Discord server or simply contact us.

chevron_up