Practice Assignment: Variables and Data Types
Practice Assignment: Variables and Data Types
Practice variables, constants, data types, variable declaration, initialization, naming rules, typing systems, and type conversion through beginner-friendly language-neutral exercises.
Assignment Overview
This practice assignment is designed to help students revise and apply the concepts of variables and data types. Students will identify data types, declare variables, initialize values, apply naming rules, use constants, perform type conversion, and write simple language-neutral pseudocode.
The purpose of this assignment is not to memorize syntax from a specific programming language. Instead, students should understand the logic behind how data is stored, named, converted, and used in a program.
Learning Objectives
After completing this assignment, students should be able to:
Objectives
- Identify common data types from given values.
- Choose suitable variable names for different values.
- Differentiate between variables and constants.
- Declare and initialize variables using language-neutral pseudocode.
- Understand static typing and dynamic typing examples.
- Understand strong typing and weak typing behavior.
- Apply type conversion and type casting where needed.
- Write small pseudocode programs using variables and data types.
- Detect common mistakes related to variables and data types.
- Improve readability using meaningful names and clear data handling.
Prerequisites
Before attempting this assignment, students should revise the following topics:
Required Topics
- What is data?
- What is a data type?
- Why data types are needed.
- Common data types.
- Variables and constants.
- Variable declaration and initialization.
- Variable naming rules.
- Static typing vs dynamic typing.
- Strong typing vs weak typing.
- Type conversion and type casting.
Assignment Instructions
Read each task carefully and write your answers clearly. Use language-neutral pseudocode where coding is required.
x, y, a, or temp unless there is a clear reason.
General Instructions
- Write answers in a clean and organized way.
- Use pseudocode, not any specific programming language.
- Use
DECLARE,SET,INPUT,DISPLAY, andCONVERTwhere needed. - Clearly mention data types where required.
- Use constants for fixed values.
- Use type conversion before performing calculations with text input.
- Check your variable names for readability.
Task 1: Identify Data Types
Identify the most suitable data type for each value.
| Value | Your Answer: Data Type |
|---|---|
25 |
________________________ |
99.75 |
________________________ |
"Programming Mastery" |
________________________ |
true |
________________________ |
'A' |
________________________ |
[80, 75, 90] |
________________________ |
{name: "Ravi", age: 18} |
________________________ |
null |
________________________ |
Task 2: Choose Better Variable Names
Rewrite the poor variable names using meaningful names.
| Poor Variable Name | Stored Value | Better Variable Name |
|---|---|---|
x |
Student age | ________________________ |
n |
Student name | ________________________ |
p |
Product price | ________________________ |
q |
Product quantity | ________________________ |
m |
Total marks | ________________________ |
flag |
Login status | ________________________ |
arr |
List of student names | ________________________ |
Task 3: Declare Variables
Write language-neutral variable declarations for the following requirements.
DECLARE variableName AS dataType
| Requirement | Your Declaration |
|---|---|
| Declare a variable to store student name. | ________________________ |
| Declare a variable to store age. | ________________________ |
| Declare a variable to store product price. | ________________________ |
| Declare a variable to store pass/fail status. | ________________________ |
| Declare a variable to store list of marks. | ________________________ |
Task 4: Initialize Variables
Initialize variables with suitable starting values.
DECLARE variableName AS dataType = initialValue
1. Create and initialize a variable for student name.
2. Create and initialize a variable for student age.
3. Create and initialize a variable for average marks.
4. Create and initialize a variable for login status.
5. Create and initialize a variable for total amount.
Task 5: Variables vs Constants
Decide whether each value should be stored as a variable or constant.
| Value / Situation | Variable or Constant? | Reason |
|---|---|---|
| Student marks entered by user | ________________ | ________________________ |
| Minimum pass mark: 35 | ________________ | ________________________ |
| Number of days in a week: 7 | ________________ | ________________________ |
| Current score in a game | ________________ | ________________________ |
| Maximum login attempts: 3 | ________________ | ________________________ |
Task 6: Type Conversion
The following values are stored as text. Convert them into suitable numeric types before calculation.
SET priceText = "250.50"
SET quantityText = "2"
SET totalAmount = priceText * quantityText
DISPLAY totalAmount
Your Task
Rewrite the pseudocode correctly using type conversion.
WRITE YOUR CORRECTED PSEUDOCODE HERE
Task 7: Static Typing or Dynamic Typing?
Identify whether the following pseudocode represents static typing style or dynamic typing style.
Example A
DECLARE studentName AS TEXT = "Ravi"
DECLARE age AS INTEGER = 18
DECLARE isPassed AS BOOLEAN = true
Typing style: ________________________
Example B
SET studentName = "Ravi"
SET age = 18
SET isPassed = true
Typing style: ________________________
Task 8: Strong Typing or Weak Typing Behavior?
Read the behavior and identify whether it shows strong typing behavior or weak typing behavior.
| Behavior | Strong or Weak Typing? |
|---|---|
| The program refuses to add text and number without conversion. | ________________________ |
The program automatically converts 10 into "10" and joins text. |
________________________ |
| The program requires explicit conversion before calculation. | ________________________ |
The program silently converts "5" into a number during subtraction. |
________________________ |
Task 9: Find the Mistakes
Identify the mistakes in the following pseudocode and rewrite it correctly.
DECLARE student name AS TEXT
SET student name = Ravi
DECLARE marks AS TEXT = "80"
DECLARE bonusMarks AS INTEGER = 5
SET finalMarks = marks + bonusMarks
DISPLAY finalMarks
Mistakes to Find
- Invalid variable name.
- Missing quotation marks for text.
- Marks stored as text but used in calculation.
- Type conversion required before addition.
Write Corrected Version
WRITE YOUR CORRECTED PSEUDOCODE HERE
Task 10: Mini Program - Student Result Calculator
Write language-neutral pseudocode for a student result calculator.
Requirements
- Input student name.
- Input marks for three subjects.
- Calculate total marks.
- Calculate average marks.
- Use a constant named
PASS_MARKwith value35. - If average marks are greater than or equal to
PASS_MARK, displayPass. - Otherwise, display
Fail. - Use meaningful variable names.
- Use proper data types.
Your Pseudocode
WRITE YOUR STUDENT RESULT CALCULATOR PSEUDOCODE HERE
Task 11: Mini Program - Simple Billing System
Write pseudocode for a simple billing system.
Requirements
- Input product name.
- Input product price as text.
- Input quantity as text.
- Convert product price to decimal.
- Convert quantity to integer.
- Calculate total amount.
- Display final bill message.
- Use meaningful variable names.
Your Pseudocode
WRITE YOUR SIMPLE BILLING SYSTEM PSEUDOCODE HERE
Submission Checklist
Before submitting, check whether your assignment follows these points.
Checklist
- All variable names are meaningful.
- Variable names do not contain spaces.
- Constants are used for fixed values.
- Data types are suitable for stored values.
- Variables are initialized before use.
- Text values are converted before numeric calculations.
- Pseudocode is written clearly.
- Output statements are meaningful.
- Type conversion is used where required.
- Answers are neat and easy to read.
Bonus Challenge
Create a small profile summary program using variables and data types.
Requirements
- Store student name as text.
- Store age as integer.
- Store course name as text.
- Store completion percentage as decimal.
- Store certificate eligibility as boolean.
- Display all information in a readable format.
Bonus Pseudocode Area
WRITE YOUR BONUS PROGRAM HERE
Evaluation Rubric
The assignment can be evaluated using the following rubric.
| Criteria | Marks | What to Check |
|---|---|---|
| Data Type Identification | 10 | Correctly identifies common data types. |
| Variable Naming | 10 | Uses meaningful and valid variable names. |
| Declaration and Initialization | 15 | Declares and initializes variables correctly. |
| Variables and Constants | 10 | Correctly chooses variable or constant based on usage. |
| Type Conversion | 15 | Uses conversion where needed before calculations. |
| Pseudocode Logic | 20 | Writes clear and logical pseudocode programs. |
| Debugging and Correction | 10 | Finds and corrects variable and type-related mistakes. |
| Presentation and Readability | 10 | Answers are neat, organized, and readable. |
Sample Answer Key
This answer key can be used by instructors for checking. Students should attempt the assignment first before viewing the answers.
Task 1: Data Types
| Value | Data Type |
|---|---|
25 |
Integer |
99.75 |
Decimal / Float |
"Programming Mastery" |
String / Text |
true |
Boolean |
'A' |
Character |
[80, 75, 90] |
List / Array |
{name: "Ravi", age: 18} |
Object / Record |
null |
Null / Empty Value |
Task 6: Corrected Type Conversion
SET priceText = "250.50"
SET quantityText = "2"
SET price = CONVERT priceText TO DECIMAL
SET quantity = CONVERT quantityText TO INTEGER
SET totalAmount = price * quantity
DISPLAY totalAmount
Task 9: Corrected Mistake Example
DECLARE studentName AS TEXT
SET studentName = "Ravi"
DECLARE marksText AS TEXT = "80"
DECLARE bonusMarks AS INTEGER = 5
SET marks = CONVERT marksText TO INTEGER
SET finalMarks = marks + bonusMarks
DISPLAY finalMarks
Task 10: Student Result Calculator Sample
CONSTANT PASS_MARK = 35
CONSTANT SUBJECT_COUNT = 3
ENTRY POINT
DECLARE studentName AS TEXT = ""
DECLARE mathMarks AS INTEGER = 0
DECLARE scienceMarks AS INTEGER = 0
DECLARE englishMarks AS INTEGER = 0
DECLARE totalMarks AS INTEGER = 0
DECLARE averageMarks AS DECIMAL = 0.0
DECLARE resultStatus AS TEXT = ""
INPUT studentName
INPUT mathMarks
INPUT scienceMarks
INPUT englishMarks
SET totalMarks = mathMarks + scienceMarks + englishMarks
SET averageMarks = totalMarks / SUBJECT_COUNT
IF averageMarks >= PASS_MARK THEN
SET resultStatus = "Pass"
ELSE
SET resultStatus = "Fail"
END IF
DISPLAY studentName
DISPLAY totalMarks
DISPLAY averageMarks
DISPLAY resultStatus
END ENTRY POINT
Task 11: Simple Billing System Sample
ENTRY POINT
DECLARE productName AS TEXT = ""
DECLARE priceText AS TEXT = ""
DECLARE quantityText AS TEXT = ""
DECLARE price AS DECIMAL = 0.0
DECLARE quantity AS INTEGER = 0
DECLARE totalAmount AS DECIMAL = 0.0
DECLARE billMessage AS TEXT = ""
INPUT productName
INPUT priceText
INPUT quantityText
SET price = CONVERT priceText TO DECIMAL
SET quantity = CONVERT quantityText TO INTEGER
SET totalAmount = price * quantity
SET billMessage = "Total amount for " + productName + " is " + CONVERT totalAmount TO TEXT
DISPLAY billMessage
END ENTRY POINT
Quick Summary
| Concept | What Students Practiced |
|---|---|
| Variables | Creating named containers for values. |
| Data Types | Identifying the correct type for each value. |
| Constants | Using fixed values such as pass marks and limits. |
| Declaration | Introducing variables with names and types. |
| Initialization | Giving variables their first values. |
| Naming Rules | Writing meaningful and valid variable names. |
| Type Conversion | Converting text input into numbers before calculation. |
| Pseudocode | Writing language-neutral logic clearly. |
Final Takeaway
This assignment helps students practice one of the most important foundations of programming: working with variables and data types. Students should understand that variables store values, data types describe those values, constants protect fixed values, and type conversion helps data work correctly in calculations and output. Mastering these concepts will make future topics like operators, conditions, loops, arrays, functions, and objects much easier.