Skip to main content
Logo image

Section 2.5 Variables

Learning Objective:
  • Student will be able to create variables using naming conventions
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:
  1. variables can not contain spaces
  2. They typically do not start with numbers
  3. 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.

You have attempted of activities on this page.