Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with this review Please answer the following True or False questions

ID: 3867686 • Letter: P

Question

Please help with this review

Please answer the following True or False questions: Chose the best answer

1 String variable X holds 'Thank' and variable Y holds 'You', then X + Y gives us ‘ThankYou’

2 In python programming, If variable X = ‘2’ and variable Y = ‘3’, then X + Y gives 5

3 A variable is a name for a place in the computer's memory where you store some data

4 Before reading or writing to a file, a file object must be created via an open method

5 Python is a general-purpose interpreted, interactive, object-oriented, and high-level programming language

6 Python = 'Hello World!', python[0] will produce

7 Pseudo-random generators generate true random numbers

8 In python lists are mutable and they have dynamic nature

9 The principles of OOP include polymorphism, encapsulation, inheritance and abstractions

10 Assume the following python code, list = [ 'abcd', 786 , 2.23, 'john', 70.2 ], list[-1] and list[5] gives us the same output

11 ** operator performs exponential (power) calculation. a**b = 10 to the power 20 if a = 10 and b = 20

12 Break statement terminates the loop statement and transfers execution to the statement immediately following the loop

13 In Python the capitalize() funciton Converts all lowercase letters in string to uppercase

14 The output of len([1, 2, 3]) is 2

15 list.reverse () sorts objects in a list

Explanation / Answer

(1)
   Both X and Y holds two strings. Both strings can be concatenated in to a single string using + operator.
   Hence X + Y gives 'ThankYou'
  
   Hence given statement is TRUE

________________________________________________________________________________________________________

(2)
   Both X and Y holds two strings. Operator + concatenates both the strings.
   Hence X + Y returns '23' but not 5.
  
   Hence given statement is FALSE
________________________________________________________________________________________________________

(3)
   Variable name is the one used to reference the value stored in memory.
  
   Hence given statement is TRUE
  
________________________________________________________________________________________________________

(4)
   Before reading / writing to a file, a file object needs to be created using open method and need to specify the mode of reading(read or write).
  
   For eg:
      
       For Reading: fReader = open("fileName", "r");
       For Writing: fWriter = open("fileName", "w");
      
   Hence given statement is TRUE
  
________________________________________________________________________________________________________

(5)
   Python language was created by Guido van Rossum during 1985- 1990.
  
   It has following features:
       (a)   Interpreted - Translates each line of code individually
       (b)   Interactive - Python comes up with excellent IDE that gives user friendly interactive environment
       (c) Object-Oriented - Python offers excellent OOPS features where in reduces complexity and increases usability.
       (d)   High Level Programming Language - Commands are mostly direct commands specified in high level language.
      
   Hence given statement is TRUE
  
________________________________________________________________________________________________________

(6)
   Statement python = 'Hello World!'; stores the string 'Hello World!' in to variable python.
  
   python[0] refers to character 'H' present at index 0 of string 'Hello World!' pointed by variable python.
  
________________________________________________________________________________________________________

(7)
   Pseudo-random number generator (PRNG) are used for generating sequence of numbers that are close to truly random that are generated using hardware random number generators.
  
   Hence given statement is TRUE
________________________________________________________________________________________________________

(8)
   Python objects (lists, dictionaries) are mutable in nature i.e., With out losing their identity, values can be changed. Hence Lists are considered to mutable in nature.
  
   For eg:   myList = [10, 20, 30]
  
   myList[1] = 50; changes the list to myList = [10, 50, 30]
   
   Hence given statement is TRUE
  
________________________________________________________________________________________________________

(9)
   OOP Principles:
   (a) Polymorphism - Refers to Single name many forms. A function can be defined with same name but tends to exhibit different feature based on Change in Parameters.
   (b)   Encapsulation - Hides the data and implementation details from outside world.
   (c) Inheritance - Refers to object re-usability. Parent class features can be used by child class rather than implementing once again.
   (d) Abstraction - It hides all the unwanted data and focuses mostly on its usability rather than on its implementation.
  
   Hence given statement is TRUE
  
________________________________________________________________________________________________________

(10)
   Give list declaration, list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
  
   List indexing starts from 0 to 4 (both including).
  
   list[-1] refers to last element in the list.
  
   list[5] generates an error as it exceeds the indexing value.
  
   Hence given statement is FALSE
  
________________________________________________________________________________________________________

(11)
   Operator ** calculates exponential (power).
  
   For eg: 2**4 returns value 16
  
   Hence given statement is TRUE
  
________________________________________________________________________________________________________

(12)
   Break statement terminates the loop statement and transfers execution to the statement immediately following the loop.
  
   For eg:
      
       for ch in 'Hello World!':
           if letter == 'r':
               break
      
       print(ch, end="")
      
       Generates following output:
          
           Hello Wo
          
       (Whenever character r encounters loop gets terminated using break statement and hence output contains Hello Wo)
  
   Hence given statement is TRUE
  
________________________________________________________________________________________________________

(13
   Function capitalize() in python turns Starting character of string to upper case and remaining all characters to lower case.

   Hence given statement is FALSE
  
________________________________________________________________________________________________________

(14)
   Statement len([1, 2, 3]) returns value 3.
  
   [1, 2, 3] is a list. Function len() will return length of the string. As there are three elements in the list. Statement len([1, 2, 3]) returns value 3 but not 2.
  
   Hence given statement is FALSE
  
________________________________________________________________________________________________________

(15)
   list.reverse () doesn't sorts objects in a list. It just reverses the elements of the list.
  
   For eg:
      
       a = [1, 4, 2, 9]
      
       a.reverse() turns a into [9, 2, 4, 1]

       Hence given statement is FALSE
  
________________________________________________________________________________________________________