Section 2.5 Variables
You might notice that every time we display the prompt we take the user’s input and store into the class# variable. What we are doing here is called an assignment. We are setting the value of the Variable to be something so that later on we can perform calculations with it later.
You are allowed to name your variables whatever you wish however, there are some restrictions depending on the programming language you are using and also some conventions that are widely adopted among programmers. The general restrictions are:
variables can not contain spaces
They typically do not start with numbers
They typically can not be characters that are not numeric, alphabetical, or under_scores.
Exercises Exercises
1.
Which of these are valid variable names?
num
Yes, num is correct.
class_4
Yes, class4 is correct.
44t
Remember that variables cannot start with numbers
comp science
Remember that variables cannot have spaces between them
Hint.Variables cannot start with numbers and cannot have spaces between them.
Often programmers use camelCase. camelCase is the practice of writing phrases without spaces or punctuation, indicating the separation of words with a single capitalized letter, and the first word starting with either case. Another style is snake_case, which uses under_scores to represent spaces
Exercises Exercises
1. Clickable Areas, Code.
Identify (by clicking) all of the assignment statements that have used camel case.
Remember, the operator =
is used for assignment.
show = "hello_world"
num_1 = 40
numThree = 55
num_2 = 30
varShow = False
You have attempted
of
activities on this page.