Page 1 :
SANSKAR GLOBAL SCHOOL, Teunga, Pratapgarh (U.P.), , Subject- Computer, Session-(2020-21), th, , Class-7, , Chapter 9- VARIABLES and DATA TYPES IN PYTHON, Note: - Copy Ques-Ans to your fair copy. Do exercise in your book., , EXERCISE, A. Multiple choice questions(MCQ)., 1. Which of the following is a valid variable name?, a) total_marks b) total@marks c) $totalmarks, , Ans. A, , 2. Which of the following is a reserved word in Python?, a) export, b) field, c) import, , Ans. C, , 3. Which of the following sign is used to concatenate strings?, a) b) +, c) *=, , Ans. B, , 4. Which of the following is not a standard data type?, a) Numbers, b) List, c) Operators, , Ans. C, , 5. Which of the following is an assignment statement?, a) X=5, b) X > 5, c) 5 = X, , Ans. A, , B. Fill in the blanks:1. A variable is a quantity which can store value in the computer, memory., 2. The = sign is used to assign value to a variable., 3. ‘=’ is known as assignment operator., 4. The String is ordered sequence of letters., 5. The * operator is used to repeat a string for a given number of times.
Page 2 :
C. Identify the name of valid and invalid variable names among, the following given names. Also specify the reason for invalid, variable names., Epode, Emp.code, elif, _empcode, emp_code11, Emp#code, 9 empcode, , Ans C. Invalid variable names are: Emp.code, elif, Emp#code, 9, empcode., D. Write the output for the following code., Code, , 1. >>> a = 10, >>> print (a), 2. >>> x= 4, >>> y = x* 4, >>>print(y), 3. >>> z= “five”, >>> print (z), 4. >>> print (“Welcome to” + “Python”), , Output, , 10, , 16, five, Welcome to Python, , E. Short answer type questions., Q1. What is a variable?, Ans1. A variable is a quantity which can store value in computer, memory. It is a quantity whose value changes during the, execution of a program., Q2. What is concatenation of string?, Ans2. The concatenation operation is used for adding two strings. This, can be achieved by adding ‘+’ operator between the two strings., Q3. What is iteration of string?, Ans3. Iteration of string is repetition of string . The * operator can be used, to repeat the string for a given number of times., Q4. What is an assignment statement?, Ans4. An assignment statement associates a value with a variable. It, creates new variables and gives them values.
Page 3 :
F. Long answer type questions., Q1. Explain any two data types supported by Python., Ans1. Data Type, Description, Number, Number data type stores, numerical values. The value of the, object of this data type cannot, be changed. These data type can, be integer (+ or – sign with numbers),, fractions or decimals., Data Type, Description, String String is an ordered sequence of letters/, characters. They are enclosed in single, quotes (‘ ’) or double (“ “) The quotes are not, part of string. They only tell the computer, where the string constant begins and ends., The plus (+) sign is the string concatenation, operator and the asterisk (*) is the repetition, operator., , Example, y=12.75, var2= 87, , Example, str =’Hello World!’, print (str*2), # prints string twice, Output:, Hello World!, Hello World!, , Q2. Explain the rules of naming a variable., Ans2. Rules for naming a variable are:, • Variables name should be descriptive., • It must begin with a letter (a - z, A - Z) or underscore (_)., • It should start with a lowercase letter. Example x, y, z, etc., • A variable name can contain alphabets, digits and underscore. No other, character is allowed.25
Page 4 :
• The words can be separated by underscore(_) followed by more letters,, underscores or digits (0 to 9)., • Python does not allow punctuation characters such as @, $ and %., Spaces are also not allowed., • There are reserved or keywords in Python that can not be used as a, variable name., G. Application based questions., Q1. Jatin had written a Python code and he used name@5 as variable name., As he pressed Enter key, syntax error was shown by the interpreter., What could be the possible reason for the syntax error?, Ans1. He has used an invalid variable name. Python does not allow, punctuation characters such as @, $ and % while naming a variable., Q2. Shubhangi wants to write a Python code to repeat her computer book’s, name five times. How can she display this?, Ans2. She wants to iterate the name of her computer book. For this she can, use * operator., >>>str= “Cyber Hub”, >>>print (str*5)