BANA3020 Lab2
BANA3020 Lab2
BANA3020 Lab2
(a) No submission by the deadline will incur 0.25 point deduction for each problem (most of the
problems are due at the end of the lab session).
(b) The instructor will deduct an additional 0.25 point per problem for each day past the deadline.
(c) The penalty will be deducted until the maximum possible score for the lab practice reaches zero
(0%) unless otherwise specified by the instructor.
Now we can output information to the user, but how can we ask the for their input? Here is where you can
use the aptly named input function. Which prompts the user for a string input that we can use for the rest
of our program.
The syntax for the input function is: input("Your prompt here"), and will give whatever the user decides
to enter as a string.
In the examples for the rest of the semester, the text in teal represents what the user inputs, and the text
in violet represents our code to be executed by the Python interpreter. In the following example, the user
enters BANA3020. Which we can use to print a corresponding welcome message.
Note that the return type of input() is a string. Recall that we have different data types in Python for
numbers and text (int for whole numbers, float for real numbers, str for text strings). Therefore, when
we prompt the user to enter a numerical value, we have to convert its type accordingly to be able to use it as
a number. Otherwise, you will get unexpected behaviour (often referred to as a bug)!
You can use int(), float(), str(), and more to convert a value into a data type that you would like it to
be. Be careful, not all conversion makes sense! e.g. What would int("Hello!") gives?