Viva
Viva
o Interpreter
2. What are the built-in types available in python?
o Numbers, Strings, Lists, Tuples, Dictionaries
3. How python interpreter interprets the code?
o Python interpreter interprets the code line by line.
4. Name a few mutable data types of python.
o Lists, Sets, and Dictionaries
5. Name a few immutable data types of python.
o Strings, Tuples, Numeric
6. What is the significance of a pass statement in python?
o pass is no operation python statement. This is used where python requires syntax but logic
requires no actions.
7. What is slicing in python?
o Python slicing is a statement of python that extracts a list of elements from the given
sequence in the range of start and stop values with step value intervals.
8. What are comments in python?
o Python comments are nonexecutable text written in the python program to give a description
for a statement or group of statements.
9. How to print list l in reverse order in a single line statement?
o print(l[::-1])
10.Python string can be converted into integer or float?
o If the string contains only numbers it can be converted into an integer or float using int() and
float() functions.
11.What is the difference between / and //?
o / is used for division, // is used for floor division
o / returns float as answer whereas // returns integer as answer
o / gives you the number with decimal places whereas // gives you only integer part
12.How to check the variables stored in same object in python?
o The id() function returns the memory address of python object.
13.What are the parameters of print() function? Explain.
o The print function has three parameters:
message – Contains the message to be printed
sep – It is onptional parameter used to print a separator
end – It prints the endline character
14.What is the significance of ‘else’ in loops in python?
o Else block is written in pyton progrm when loop is not satisfying the condition. It gets executed
when the while loop’s condition is false where as in for loop it executes when for loop ends
normally.
15.Divya is learning python. She wants to know the version of python using python
programming statements. Please help her to accomplish her task.
o >>> import sys
o >>> sys.version
16.How to remove the last element from a list?
o To remove the last element from a list following ways can be used:
l.pop()
del l[-1]
17.What is the difference between append() and extend() methods?
o append() is used to add an element to the list to the last.
o extend() is used to add multiple elements to the list.
18.Consider the statement: L = [11,22,33,[45,67]], what will be the output of L[-2+1}?
o [45.67]
19.What is tuple unpacking?
o Tuple unpacking refers to extracting tuple values into a separate variable.
20.What are the two ways to insert an element into dictionary?
o Method 1 – Modifying a dictionary with fresh key and value ex. d={1:’A’,2:’B’}; d[3]=’C’
o Method 2 – With a function setdefault ex. d={1:’A’,2:’B’};d.setdefault(3,’C’)
21.Samira wants to remove an element by value. Suggest her a function name to accomplish
her task.
o l.remove(value)
22.How to remove all elements of a list?
o There are two ways to remove all elements of list
Using clear – l.clear()
Using del – del l
23.How del is different from clear?
o del removes entire list object where clear() just removes elements and makes list empty
24.What is a function?
o A function is a subprogram and a smaller unit of a python program consists of a set of
instructions and returns a value.
25.Does every python program must return a value?
o No, not every python program returns a value.
26.What are the parts of a function?
o A python function has the following parts:
Function header – Starts with def keyword followed by function name and parameters
Function body – Block of statements/instructions that define the action performed by the
function, indentation must be followed
Function caller statement – writing function name including parameter values
27.What are the needs of function in the python program?
o Easy program handling
o Reduce the size of the program
o Reduce the repeated statements
o Ambiguity can be reduced
o Make program more readable and understandable
28.How to call your function through python interactive mode?
o Save a program if not saved and click on Run > Run Module or press the F5 button from the
python script mode
o Now interactive mode will appear with the message RESTART ……
o Write a function call statement with function name and list of parameter values in the
brackets
o A function call statement is just like a function name with required parameters
o Press enter and supply input as per requirements
29.What are void functions? Explain with example?
o The void functions are those functions that do not return any value.
o Python function which does not contain any return statement and having a bunch of different
print statements are called void functions.
o Python supports a special object “nothing” or None datatype.
30.Observe the following lines of code and identify function definition or function caller
statement:
o myfun(“TutorialAICSIP”,2020) – function caller with positional arguments
o myfun(name=”TutorialAICSIP”,year=2020) – function caller with default arguments
o def myfun(name, year=2020) – function definition with default argument
o myfun(name=”TutorialAICSIP”,year) – function caller but reaise an error
31.What are the physical line and logical line structure in python program?
o The physical lines in python programs contain EOL (End Of Line) character at the point of
termination of lines
o The logical lines in python programs contain white spaces or tab or comment at the point of
termination of lines
32.What is indentation? Explain its importance in two lines.
o Indentation refers to white spaces added before each line of the code.
o In python, it detects the block of code.
o It also makes the program more readable and presentable.
o It organizes the code of blocks in a good manner.
33.What is a top-level statement in python?
o The python unindented statements in python programs are considered as a top-level-
statement.
o _main_ is also a python top-level statement
34.What are the comments? Explain the role of comments in the python programs?
o Comments are non-executable parts of python programs.
o You can write a comment for the description or information related to statements, basic
details of programs etc.
o There are two types of comments:
Single-Line: These comments written for explaining single line comments, begins with #
Multi-Line: These comments written for explaining multi-line comments, begins and ends with
”’ triple quotes
35.Does python program functions contain multiple return statements and return multiple
values?
o Yes, python program functions can have multiple return statements.
o To return multiple values you can write values with return keyword separated by comma
36.What do you mean by fruitful and non-fruitful functions in python?
o The functions which return values are called fruitful functions.
o The function not returning values are called non-fruitful functions.
37.Which three types of functions supported by python?
o Python supports the following three types of functions:
Built-in Functions
Functions defined in modules
User-defined functions
38.What are parameters and arguments in python programs?
o Parameters are the values provided at the time of function definition. For Ex. p,r and n.
o Arguments are the values passed while calling a function. For Ex. princ_amt, r, n in main().
39.Which types of arguments supported by Python?
o Python supports three argument types:
Positional Arguments: Arguments passed to a function in correct positional order, no. of
arguments must match with no. of parameters required.
Default Arguments: Assign default to value to a certain parameter, it is used when the user
knows the value of the parameter, default values are specified in the function header. It is
optional in the function call statement. If not provided in the function call statement then the
default value is considered. Default arguments must be provided from right to left.
Key Word Arguments: Keyword arguments are the named arguments with assigned values
being passed in function call statement, the user can combine any type of argument.
Variable Length Arguments: It allows the user to pass as many arguments as required in the
program. Variable-length arguments are defined with * symbol.
40.What are the rules you should follow while combining different types of arguments?
o An argument list must contain positional arguments followed by any keyword argument.
o Keyword arguments should be taken from the required arguments preferably.
o The value of the argument can’t be specified more than once.
41.What do you mean by python variable scope?
o The python variable scope refers to the access location of the variable defined in the program.
o A python program structure has different locations to declare and access the variable.
o There are two scopes of variables in python:
Local Scope
Global Scope
42.What is the local and global scope variable?
o The variable which is declared inside a function and can be accessible inside a function is
known as local variable scope.
o The variable declared in top-level statements of the python program is called a global variable
scope, it is accessible anywhere in the program.
43.What is the full form of LEGB? Explain in detail.
o LEGB stands for Local-Enclosing-Global-Buil-in.
o Python checks the order of variable in a program by the LEGB rule.
o First, it checks for the local variable, if the variable not found in local then it looks in enclosing
then global then built-in environment.
44.What are mutable and immutable arguments/parametersin a function call?
o Mutable arguments/parameters values changed over the access of value and variable at
runtime.
o Immutable arguments/parameters whose values cannot be changed. They allocate new
memory whenever the value is changed.
45.What are modules in python?
o A large program is divided into modules.
o A module is a set of small coding instructions written in a programming language.
o These modules create a library.
o A python module is a .py that contains statements, classes, objects, functions, and variables.
o That allows reusing them anytime by importing the module.
o The structure of the python module plays an important role in python library functions.
46.Name few commonly used libraries in python.
o Standard library
o Numpy Library
o Matplotlib
o SciPy
47.What do you mean docstrings in python?
o Docstrings is the triple quoted text of the python program.
o It provides comments related to the authors of the program, details about functions, modules,
classes.
o The docstrings contents written in the module can be accessed through help().
48.Is there any difference between docstrings and comments?
o The docstrings and comments ignored by the python interpreter in execution.
o But the docstring provides the information about modules, functions or classes which can be
accessed by help() function.
49.What is the use of dir() function?
o The dir() function is used to display defined symbols in the module.
50.What are the two ways to import modules?
o You can import modules in python using these two ways:
import <modulename>
from <module> import <object>
51.What is a file?
o A file is a stream of bytes stored on secondary storage devices having an extension.
52.What are the different modes of opening a file?
o The different modes of opening a file are as follows:
r,w,a,r+,w+,a+,rb,wb,ab,rb+,wb+,ab+
53.If no mode is specified in open() function, which mode will be considered?
o r
54.What is the difference between “w” and “a” mode?
o “a” mode adds the content to the existing file whereas “w” mode overwrites the contents into
the file.
55.What is the difference between readline() and readlines() function?
o readline() function reads the content of the text file and returns the content into the string
whereas readlines() function reads the content of the text file and returns the content into the
list.
56.Parth wants to read only n number of characters from a text file. Suggest him a function to
accomplish his task.
o The read(n) function can be used
57.Nakshatra wants to count no. of words from the text file. Suggest her code to accomplish a
task.
o f=open(“one.txt”)
o w=f.read().split()
o c=0
o for i in w:
c+=1
print(c)
58.What are the two different types of text files?
o Plain text or regular text files
o Delimited text files or separated text files
59.What are full forms of: a) csv b) tsv
o csv – comma separated values
o tsv – tab-separated values
60.Are CSV files and Text Files same?
o CSV files and Text Files are same in storage but csv file stores the data separated by a
delimiter.
61.What are the different valid delimiters?
o , is default delimiter
o other delimiters are tab – \t, colon – :, or semi colon – ;
62.What is pickling?
o Pickling refers to the process of converting python object hierarchy into a byte stream to write
into a binary file.
63.What is unpickling?
o It is the process of converting the byte stream back into an object hierarchy.
64.Which module is required to handle binary files?
o pickle
65.Name the functions used to read and write data into binary files.
o pickle.dump(list_object, file_handle)
o pickle.load(file_object)
66.Which error is reported while reading the file binary file?
o ran out of input
67.How to avoid reading file errors in binary file?
o By using exception handling with try and except blocks
68.What is the significance of tell() and seek() functions?
o tell() function returns the current file position in a file
o seek() function change the current file position
69.What is the default value of offset for seek function?
o 0
70.What is offset in the syntax of seek function?
o Offset refers to the number bytes by which the file object is to be moved.
71.Nimesh is working on a stack. He started deleting elements and removed all the elements
from the stack. Name this situation.
o Stack underflow
72.What are the operations can be performed on the stack?
o Push
o Pop
o Peep or Peek
73.Which principle is followed by stack?
o LIFO (Last in First Out)
74.Name any three applications of stack.
o Call history on mobile
o Browser history
o Undo and redo commands
o CD/DVD tracks
o Books on the tables
75.What is an exception in python?
o An error or unusual condition that occurs in the program that causes abnormal termination of
the program or crash of the python program is called an exception.
76.What do you mean by debugging?
o The process of finding program errors is called debugging.
77.Tell me the three basic types of errors that occur in Python.
o Syntax Errors
o Logical Errors
o Run-Time Errors
Project questions
Code Structure and Organization:
Game Functions:
Question: Can you explain how the Word Guessing Game works?
Answer: The Word Guessing Game prompts the user to guess a target word ("python"). The user
enters single letters, and if the letter is in the word, it gets revealed. The game continues until
the entire word is guessed.
Question: How are points updated and stored for each game?
Answer: Points are updated using the update_points_csv function, which modifies the 'Points'
column in the respective game's CSV file. Points are stored as integers and represent the user's
score for each game.
Question: Explain the logic of the Quiz, Rock-Paper-Scissors, and Math Quiz games.
Answer: The Quiz game asks a series of multiple-choice questions, scoring the user based on
correct answers. Rock-Paper-Scissors involves the user choosing one of the three options, and
points are awarded based on the outcome. The Math Quiz generates random arithmetic
questions, scoring the user based on correct answers.
Error Handling:
Question: How does the code handle PermissionError when writing to CSV files?
Answer: The code catches a PermissionError and prints a message indicating that it's unable to
write to the specified file due to permission issues. It advises the user to check file permissions.
Question: What happens if a file is not found during the view_data function?
Answer: If the specified file is not found, the code catches a FileNotFoundError and prints a
message indicating that the file is not found. It advises the user to check the file path.
Admin Panel:
Question: Explain the purpose of the admin panel and its functionalities.
Answer: The admin panel provides access to view data from each game (Word, Quiz, Rock-
Paper-Scissors, Math). It requires a password for access and allows the administrator to choose
which game's data to view.
Question: How is access to the admin panel restricted, and why is an admin password used?
Answer: Access is restricted by requiring the user to enter a password (ADMIN_PASSWORD). The
password is a simple form of authentication to ensure that only authorized users can access the
admin panel.
Time Handling:
Question: How is the duration of the Math Quiz Game calculated?
Answer: The duration is calculated by recording the start and end times using the time module.
The difference between these times gives the total time taken to complete the Math Quiz Game.
Question: Can you explain why the datetime module is used for timestamps?
Answer: The datetime.now() function from the datetime module is used to timestamp when a
user's data is added to a CSV file. It provides a human-readable representation of the current
date and time.
Randomization:
Question: Why is the random module used in the Rock, Paper, Scissors game?
Answer: The random module is used to randomly select the computer's choice (rock, paper, or
scissors) in the Rock, Paper, Scissors game, simulating an unpredictable opponent.
Question: How is the target word selected in the Word Guessing Game?
Answer: The target word ("python") is predefined in the code. For a more dynamic approach, a
list of words could be maintained, and one could be randomly chosen for each game session.
User Experience:
Question: How user-friendly is the interface for interacting with the gaming hub?
Answer: The interface provides clear menu options for selecting games, but additional
improvements, such as providing more detailed instructions during games, could enhance the
user experience.
Question: Are there any improvements that could enhance the overall user experience?
Answer: Potential improvements could include incorporating more interactive and visually
appealing elements into the games, providing feedback on correct/incorrect answers during
quizzes, and refining the menu prompts for clarity
11.User Data Handling:
Question: How is user data inserted into the CSV files, and why is the insert_csv
function used?
Answer: The insert_csv function appends a new row with user data (phone, name,
points, timestamp) to the specified CSV file. It is used to add a new user entry for a
specific game.
Question: Why are points initialized to zero when inserting user data?
Answer: Points are initialized to zero as a starting value. They get updated later based
on the user's performance in each game.
12.Game Points Calculation:
Question: How are points calculated for the Math Quiz game, and why is there a
maximum limit of 20 points?
Answer: Points for the Math Quiz game are calculated based on the number of correct
answers. The formula min(10 * correct_answers, 20) ensures that the points do not
exceed 20, providing a capped reward for performance.
Question: Could the points calculation be customized for each game?
Answer: Yes, the points calculation can be adjusted individually for each game to reflect
different scoring systems or difficulty levels.
13.Security Measures:
Question: Do you think the current password protection for the admin panel is secure
enough?
Answer: The current password protection is basic and may not be sufficient for robust
security. In a real-world scenario, more secure authentication mechanisms like hashing
and salting should be implemented.
Question: How could you enhance security in handling user data?
Answer: Implementing encryption for sensitive data, such as passwords, and using
secure authentication methods would enhance security. Additionally, implementing
proper error handling for security-related issues is crucial.
14.Code Readability and Documentation:
Question: How would you rate the overall readability of the code?
Answer: The code is relatively readable, but improvements could be made by adding
comments to explain complex sections and functions.
Question: Are there any parts of the code that may be unclear to someone else reading
it?
Answer: Without comments, the logic behind certain game functionalities, especially
the word guessing game, may be less clear to someone reading the code for the first
time.
15.Scalability and Extensibility:
Question: How easily could new games be added to this gaming hub?
Answer: The current structure allows for relatively easy addition of new games. A new
CSV file and corresponding game function would need to be implemented.
Question: Can the code handle a large number of users efficiently?
Answer: While the code can handle multiple users, efficiency might be a concern with a
large user base. Implementing more advanced data structures or even a database could
improve performance.
16.Exception Handling in Game Functions:
Question: How does the code handle invalid user inputs during the games (e.g., entering
a non-letter in the Word Guessing Game)?
Answer: Invalid inputs are detected and appropriate error messages are displayed,
prompting the user to enter a valid input.
Question: Are there any potential pitfalls in the current approach to handling exceptions
in the game functions?
Answer: The current approach is reasonable for handling user input errors, but
additional fine-grained exception handling could be implemented to provide more
specific error messages.
17.File Path Handling:
Question: How does the code handle file paths, and why is the os.path.join function
used?
Answer: The os.path.join function is used to create platform-independent file paths. It
joins directory and file names, ensuring the correct path format regardless of the
operating system.
Question: Could there be issues with file paths on different operating systems?
Answer: Using os.path.join minimizes potential issues, but it's essential to be aware of
file path differences between operating systems, especially when sharing code