Project time!
This is a project section. These operate a bit differently than lessons or quizzes, as they allow you to use what you have learned. We will give a few rules for you to follow, and you will program accordingly. Don't worry, there's no penalty or problem if you mess up. It's all about learning. At the end of this project, you can see the answer equivalent.
Assignment & User Input
For our first mini project, you will need to create a new Python program that:
- takes in as input, a number of movie tickets
- outputs a total cost in sentence form
Each ticket costs $11.99.
To do this, you will need to use the input() function. Basically, set a variable’s value to input() and in between the (), type the question in quotes.
Then, you can use the user’s input throughout the program using the assigned variable.
age = input("Enter your age: ")
print("You are " + age + " years old!")
OUTPUT
Enter your age:
# When input is given:
Enter your age: 6
You are 6 years old!
The
input()function always gives you a string value, not an integer or float, even if you enter only a number as input. To change the datatype to an integer or float from a string, useint()orfloat()functions and put the value to be converted (can be a variable) between the().