0% found this document useful (0 votes)
31 views4 pages

Assignment On Variables in Python

The document is an assignment on variables in Python, defining what a variable is and outlining the rules for naming them. It includes multiple choice questions to test understanding of valid variable names and Python naming conventions. Recommended naming style is snake_case for better readability.

Uploaded by

loxis2379
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views4 pages

Assignment On Variables in Python

The document is an assignment on variables in Python, defining what a variable is and outlining the rules for naming them. It includes multiple choice questions to test understanding of valid variable names and Python naming conventions. Recommended naming style is snake_case for better readability.

Uploaded by

loxis2379
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Assignment on Variables in Python

Name: _______________________

Class: _______________________

Date: _______________________

Part 1: Definition of Variable


A variable is a name given to a value stored in memory. It works like a container that stores data
for later use in a program.

Example:

age = 15

name = "Moumita"

marks = 90

Part 2: Rules for Naming Variables


1. A variable name cannot start with a number.

2. No spaces are allowed in variable names.

3. Only letters, numbers, and underscore (_) are allowed.

4. Variable names are case-sensitive (age and Age are different).

5. Python keywords (like class, for, if) cannot be used as variable names.

6. Use meaningful names for better readability.

Recommended Style
Use snake_case style in Python. Example: total_marks, student_name, average_score.

Part 3: Multiple Choice Questions (10 MCQs)


Q1. Which of the following is a valid variable name?

a) 2number

b) first-number

c) first_number

d) first number

Ans: c) first_number
Q2. Which variable name is written in correct Python style?

a) FirstNumber

b) firstNumber

c) first_number

d) first-number

Ans: c) first_number

Q3. Which of the following will give an error?

a) age = 15

b) _count = 10

c) 1st_value = 100

d) total_marks = 90

Ans: c) 1st_value = 100

Q4. Identify the correct variable in the code: totalMarks = 85

a) totalmarks

b) total_Marks

c) totalMarks

d) Totalmarks

Ans: b) total_Marks
Q5. Which variable name contains an invalid character?

a) student_name

b) studentName

c) student$name

d) student1

Ans: d) student1

Q6. What will happen? my_age = 20 print(My_age)

a) It prints 20

b) It prints my_age

c) It gives an error

d) It prints nothing

Ans: a) It prints 20

Q7. Which variable name is NOT allowed in Python?

a) total1

b) _total

c) class

d) total_marks

Ans: a) total1

Q8. Identify the correct variable name:

a) first name
b) firstName

c) first-name

d) first@name

Ans: b) firstName

Q9. What is wrong? marks = 90 print(mark)

a) Nothing is wrong

b) Variable name is case-sensitive

c) Variable is misspelled

d) Syntax error

Ans: c) Variable is misspelled

Q10. Which is the best variable name for storing a student's total marks?

a) tm

b) x

c) total_marks

d) t

Ans: c) total_marks

You might also like