top of page

100+ Top Practice Questions with Answers to boost your fundamentals

Updated: Apr 10, 2023


These are the practice question for the VIVA of subject IP and Python


HTML/CSS/JS



1. What is HTML

HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It is the most widely used programming language for creating websites and web applications and is used to define the structure, content, and style of a web page. HTML elements are the building blocks of HTML pages. HTML is written in the form of tags, surrounded by angle brackets, within the web page content.


2. What is CSS?

CSS (Cascading Style Sheets) is a style sheet language used for describing the look and formatting of a document written in a markup language like HTML. CSS is used to define styles for your web pages, including the design, layout, and variations in display for different devices and screen sizes.


3. What is javascript?

JavaScript is a scripting or programming language that allows you to implement complex features on web pages. It is a text-based programming language used both on the client-side and server-side that allows you to make web pages interactive. It is an interpreted language, meaning that it doesn't need to be compiled. JavaScript is most commonly used to create interactive effects within web browsers.


4. What are the types of CSS

1. Inline CSS 2. Internal/Embedded CSS 3. External CSS


5. Explain inline CSS ?

Inline CSS is CSS code that is written directly into an HTML element, instead of being placed in an external stylesheet. Inline CSS is used to apply unique styling to a single element, and can be used to override styles from external stylesheets. It is generally considered best practice to use an external stylesheet whenever possible, as it is easier to maintain and update.


6. Explain internal CSS ?

Internal CSS is a type of Cascading Style Sheet (CSS) that is used to define the presentation of a single HTML document. It is placed in the head section of an HTML page, between the <style> tags. Internal CSS is used to provide a unique style to a single HTML document, and is generally preferred over external CSS when only a single HTML document needs to be styled.


7. Explain External CSS ?

External CSS is a type of CSS (Cascading Style Sheets) that is applied to a webpage from an external source. This external source can be a separate CSS file or a style declaration embedded in an HTML document. External stylesheets allow developers to easily update the look and feel of a website without having to edit the underlying HTML code. This also allows for a more organized approach to website development, as all styling information can be stored in a single file.


8. The current version of HTML is?

The current version of HTML is HTML5.


9. Explain some popular HTML tags?

1. <p> : This tag defines a paragraph in HTML.

2. <h1> : This tag defines the largest heading size in HTML.

3. <a> : This tag defines a link in HTML.

4. <img> : This tag defines an image in HTML.

5. <div> : This tag defines a section or division in HTML.

6. <span> : This tag defines a section or division inline in HTML.

7. <ul> : This tag defines an unordered list in HTML.

8. <li> : This tag defines a list item in HTML.

9. <table> : This tag defines a table in HTML.

10. <form> : This tag defines an HTML form for user input.


10. Explain Table tag in html ?

The table tag in HTML is used to structure and present data in a tabular format. It is used to display data in a tabular form and consists of rows, columns, and cells. Each table row is represented by the <tr> tag, which contains one or more table data cells (<td> tag). The <table> tag is used to define the table, while <th> is used to define the table header. Tables can also contain caption, row group, column group, and various other elements.


11. How would you link external CSS file in html

You can link an external CSS file in HTML using the <link> tag.

<head>

<link rel="stylesheet" type="text/css" href="style.css">

</head>


12. How to create a hyperlink in HTML?

The HTML provides an anchor tag to create a hyperlink that links one page to another page. These tags can appear in any of the following ways:

  • Unvisited link - It is displayed, underlined, and blue.

  • Visited link - It is displayed, underlined, and purple.

  • Active link - It is displayed, underlined, and red.

13. What is the difference between HTML elements and tags?

HTML elements communicate to the browser to render text. When the elements are enclosed by brackets <>, they form HTML tags. Most of the time, tags come in a pair and surround content.


14. Explain the iframe tag?

An iFrame (Inline Frame) is an HTML element that allows an external webpage to be embedded and displayed on a webpage. It allows web developers to embed content into their own web pages without having to host the content themselves. It is often used to embed videos, maps, and other third-party content into a website. The iFrame tag is written as <iframe>, and the attributes used to configure the iFrame can be written within the opening tag.

15. what is svg?

SVG (Scalable Vector Graphics) is an XML-based vector image format for two-dimensional graphics with support for interactivity and animation. The SVG specification is an open standard developed by the World Wide Web Consortium (W3C) since 1999. SVG images and their behaviors are defined in XML text files. This means that they can be searched, indexed, scripted and compressed.

16. In how many ways can we position an HTML element? Or what are the permissible values of the position attribute?

There are mainly 7 values of position attribute that can be used to position an HTML element:

  1. static: Default value. Here the element is positioned according to the normal flow of the document.

  2. absolute: Here the element is positioned relative to its parent element. The final position is determined by the values of left, right, top, bottom.

  3. fixed: This is similar to absolute except here the elements are positioned relative to the <html> element.

  4. relative: Here the element is positioned according to the normal flow of the document and positioned relative to its original/ normal position.

  5. initial: This resets the property to its default value.

  6. inherit: Here the element inherits or takes the property of its parent

17. What are some of the advantages of HTML5 over its previous versions?

Some advantages of HTML5 are:-

  • It has Multimedia Support.

  • It has the capabilities to store offline data using SQL databases and application cache.

  • Javascript can be run in the background.

  • HTML5 also allows users to draw various shapes like rectangles, circles, triangles, etc.

18. What is the difference between <figure> tag and <img> tag?

The <figure> tag specifies the self-contained content, like diagrams, images, code snippets, etc. <figure> tag is used to semantically organize the contents of an image like image, image caption, etc., whereas the <img> tag is used to embed the picture in the HTML5 document.


19. What is the purpose of the CSS margin property?

The CSS margin property is used to set the margins around an element.

20. What is the purpose of the CSS padding property?

The CSS padding property is used to set the padding around an element.

21. What type of element is the <span> tag?

The <span> tag is an inline element.

22. What is the purpose of the CSS float property?

The CSS float property is used to float an element to the left or right of its container.

23. What is the purpose of the JavaScript alert() function?

The JavaScript alert() function is used to display an alert box with a user-defined message.

24. What is the purpose of the JavaScript document.write() function?

The JavaScript document.write() function is used to write HTML output to the document.

25. What type of element is the <script> tag?

The <script> tag is a block-level element.


26. What is the purpose of the JavaScript console.log() function?

The JavaScript console.log() function is used to log messages to the browser's console.

27. What are the new features in HTML5?

The new features in HTML5 include semantic elements, audio/video support, drag and drop, local storage, geolocation, and canvas elements.

28. What are the different types of heading tags in HTML?

The types of heading tags in HTML are h1, h2, h3, h4, h5, and h6.

29. What is the purpose of the <!DOCTYPE> tag?

The <!DOCTYPE> tag is used to tell the browser which version of HTML the page is written in.

30. What is the difference between HTML elements and tags?

HTML elements are the actual content on the page, while HTML tags are used to indicate how those elements should be displayed on the page.

31. How do you create a hyperlink in HTML?

You can create a hyperlink in HTML by using the <a> tag with the href attribute.

32. What are the different types of lists in HTML?

The different types of lists in HTML are ordered lists, unordered lists, description lists, and menu lists

33. What is the difference between the <div> and <span> tags?

The <div> tag defines a division or a section in an HTML document, whereas the <span> tag is used to group inline elements in a document.

34. What is the purpose of the <meta> element?

The <meta> element is used to provide metadata about the HTML document such as keywords, description, author and other relevant information.

35. What is the purpose of the <title> element?

The <title> element is used to specify the title of the HTML document. This title will be displayed in the browser tab.

36. What is the purpose of the <head> element?

The <head> element contains information about the HTML document such as the title, meta data, styles, scripts and other relevant information.

37. What is the purpose of the <script> element?

The <script> element is used to define scripts for the HTML document such as JavaScript. These scripts can be used to manipulate the content of the HTML document.

38. What is the difference between classes and IDs in CSS?

Classes are used to group elements together and are usually used to apply common styles to multiple elements, while IDs are used to uniquely identify an element in a page and are usually used when an element needs to be specifically targeted by JavaScript or CSS.

39. What is the purpose of a CSS float?

The float property is used to float an element to the left or right of its container, allowing other elements to wrap around it.

40. What are the different ways to apply CSS to a web page?

CSS can be applied to a web page in three ways: inline, internal, and external. Inline styles are applied directly to HTML elements, internal styles are defined in the head section of the document, and external styles are stored in a separate CSS file.

41. What are the different types of CSS selectors?

There are four types of selectors in CSS: element, class, ID, and pseudo-class selectors.

42. What is the purpose of the z-index property in CSS?

The z-index property is used to control the stack order of elements. Elements with a higher z-index value will appear on top of elements with a lower z-index value.


43. What is the difference between visibility:hidden and display:none in CSS?

The visibility:hidden property hides an element but still reserves the space for it, while display:none completely removes the element and its space from the page.

44. What is the purpose of the position property in CSS?

The position property is used to specify how an element should be positioned within its containing element.

45. How can you create a responsive design using CSS?

Responsive design can be achieved using CSS media queries that detect the size of the device or viewport and then apply styles accordingly.

46. What are the different CSS units available for size and length?

CSS supports a variety of units for size and length, including px, em, %, rem, vw, and vh.

47. What is the difference between the visibility and opacity properties in CSS?

The visibility property controls whether an element is visible or hidden, while the opacity property controls the transparency of an element.

48. How Do You Create Shapes in CSS?

To create shapes in CSS, you can use the border and border-radius properties. You can also use the clip-path property to create more complex shapes.

49. What is the Difference Between a Relative and Absolute URL in CSS?

A relative URL is a URL that is relative to the location of the current document. An absolute URL is a URL that is specific to a particular document.

50. What is the Difference Between Inline and Block Level Elements?

Inline elements are elements that are displayed within the flow of the document. Examples include <span>, <a>, and <img>. Block elements are elements that create a new rectangular block and start a new line in the document. Examples include <div>, <p>, and <h1>.

51. What is Javascript?

JavaScript is a programming language most commonly used to create interactive effects within web browsers.

52. What is the correct syntax for referring to an external script called "xxx.js"?

<script src="xxx.js"></script>


53. What is the difference between var, let, and const?

Var is a keyword used to declare a variable in JavaScript. Let is similar to var but is a newer version of the keyword and allows for more control over the scope of a variable. Const is a keyword used to declare a constant, meaning the value cannot be changed.

54. What does the "this" keyword refer to in Javascript?

The "this" keyword in JavaScript refers to the object that the code is currently being executed within.

55. What is a function in Javascript?

A function in JavaScript is a block of code that can be executed when it is called. It can take in parameters, and can also return a value.

56. What is an array in Javascript?

An array in JavaScript is an ordered collection of data that can hold multiple values of different data types.

57. What is the difference between == and === in Javascript?

== checks if two values are equal in terms of value, while === checks if two values are equal in terms of both value and type.


Python is a high-level, interpreted programming language that is widely used for web development, data analysis, artificial intelligence, and scientific computing. It is known for its simplicity, readability, and flexibility, as well as its extensive standard library and a large community of users and developers.


Python is an object-oriented language, which means that it is based on the concept of "objects", which are data structures that contain data and methods that operate on that data. Python also supports procedural and functional programming styles, as well as asynchronous programming and generators.


58. Python is an interpreted language. Explain.

In an interpreted language, the source code is not compiled into machine code which the computer can directly execute. Instead, the source code is interpreted by a program at runtime. This means that the code is read and executed line by line as it is encountered, rather than being translated into machine code and executed all at once.


59. Difference between list and tuples



60. Features of Python

There are many features that make Python a popular and powerful programming language.

Some of these features include:

  1. High-level language: Python is a high-level language, which means that it abstracts away many of the low-level details of computer hardware and operating systems. This makes it easier to write and understand Python code.

  2. Object-oriented: Python is an object-oriented language, which means that it provides a structure for organizing code in a way that is easy to reuse and modify.

  3. Portable: Python code can run on any device that has an interpreter, making it a portable language.

  4. Dynamically-typed: In Python, you don't need to specify the data type of a variable when you declare it. The interpreter figures out the data type at runtime.

  5. Interpreted: As an interpreted language, Python code is executed line by line, which makes it easy to write and debug.

  6. Highly scalable: Python is used to build large-scale applications and can handle hundreds of thousands of lines of code.


61. What is a dictionary in Python?

In Python, a dictionary is an unordered collection of data values that are stored as key-value pairs. It is similar to a map in other languages or a hash table in data structures.


62. What is __init__ in Python?

In Python, __init__ is a special method that is called when an object is created from a class. It is known as the "constructor" method, and is used to initialize the object's properties.

Here is an example of a simple class that has an __init__ method:


class Person:

def __init__(self, name, age):

self.name = name

self.age = age


p = Person("John", 30)

print(p.name) # prints "John"

print(p.age) # prints 30


63. What are the common built-in data types on Python?

Datatypes are categories of data that are used to classify the type of information stored in a particular variable.

Python has several built-in data types, which can be grouped into the following categories:

Immutable data types:

  • Number

  • String

  • Tuple

Mutable data types:

  • List

  • Dictionary

  • Set


64. What are local and global variables?

Python, a local variable is a variable that is defined inside a function. It can only be accessed and modified within the function in which it is defined.


A global variable is a variable that is defined outside of any function. It can be accessed and modified from any part of the program.


Here is an example to illustrate the difference between local and global variables:



x = 10 # x is a global variable


def foo():

y = 5 # y is a local variable

print(y)


foo() # prints 5

print(y) # this will cause an error, because y is a local variable and is not defined outside of the function


65. What is the difference between Python Arrays and lists?



66. Is python case-sensitive?

Yes, Python is a case-sensitive programming language. This means that Python treats variables, function names, and other identifiers differently based on the capitalization of the letters in their names.

For example, in Python, the variables x and X are considered to be two different variables, because they have different capitalizations. The same is true for function names, class names, and other identifiers.


67. What are Python packages?

A package is a collection of modules that have been bundled together in a single distribution. A module is a Python script that contains definitions and statements, and a package is a collection of modules that provides a specific functionality.


68. How does break, continue, and pass work?

These statements help to change the phase of execution from the normal flow that is why they are termed loop control statements.


  • Python break: This statement helps terminate the loop or the statement and pass the control to the next statement.


  • Python continue: This statement helps force the execution of the next iteration when a specific condition meets, instead of terminating it.


  • Python pass: This statement helps write the code syntactically and wants to skip the execution. It is also considered a null operation as nothing happens when you execute the pass statement.


69. What is type conversion in Python?

In Python, type conversion is the process of converting a value from one data type to another. This can be useful when you need to perform an operation on a value, but the operation is not supported by the value's data type.


70. What is scope resolution?

scope resolution is the process of determining the correct meaning of a variable or function name in the context of your code. This is done by checking the different scopes that are available to your code and finding the variable or function with the matching name.


In Python, a scope is a region of your code where a particular variable or function is defined and can be accessed. There are several types of scopes in Python:


  • Global scope: A global scope is the top-level scope in your code. It contains all the variables and functions that are defined at the global level, outside of any functions or classes.


  • Local scope: A local scope is a scope that is defined inside a function or class. It contains the variables and functions that are defined inside the function or class, and is only accessible from within the function or class.


  • Built-in scope: A built-in scope is a predefined scope in Python that contains a set of built-in functions and variables. These include functions like “print()” and “len()”, and variables like True and False.


71. What is object-oriented programming in Python and how do you use it?

Object-oriented programming (OOP) is a programming paradigm that is based on the concept of "objects", which are data structures that contain data and methods that operate on that data. In OOP, you define classes that represent these objects, and you create instances of those classes to work with the objects.


OOP has several benefits, including:

  • Encapsulation: OOP allows you to bundle data and methods that operate on that data within a single unit, or object. This helps to keep your code organized and makes it easier to understand and maintain.


  • Abstraction: OOP allows you to hide the implementation details of a class from other parts of your code, so that you can expose a simple and clean interface to users of your code. This helps to reduce the complexity of your code and makes it easier to reuse.


  • Inheritance: OOP allows you to create a new class that is a modified version of an existing class, without having to rewrite all of the code from scratch. This can save you time and effort, and it helps to reduce duplication of code.


  • Polymorphism: OOP allows you to use the same interface for multiple types of objects, so that you can write code that can work with different types of objects in a consistent way.


72. Explain Inheritance in Python with an example?

Inheritance is a concept in Object Oriented Programming (OOP) which allows us to define a class that inherits all the methods and properties from another class.


Inheritance provides code reusability, since we can use the same methods and properties of parent class in child class.


Example:


class Animal:

def __init__(self, name):

self.name = name

def show_name(self):

print(self.name)

class Dog(Animal):

def bark(self):

print("bark")

d = Dog("Jack")

d.show_name()

d.bark()


Output:


Jack

bark


73. What are Python packages?


Python packages are pre-built directories of Python code that can be imported and used in other code. They are used to organize and share related Python code, and many packages are available on the Python Package Index (PyPI).


74. What do you mean by Python literals?


In Python, literals are data types that are used to represent certain values or data. They can be of the form of numbers, strings, booleans, etc. Examples of Python literals include: numbers (1, 2, 3), strings ("Hello World!"), booleans (True, False), and None.


75. What are the generators in python?

A generator is a special kind of function that returns an iterator.


76. What are python iterators?

In Python, an iterator is an object that produces a sequence of values, one at a time, when iterated over. An object is considered to be iterable if it is an instance of a class that defines the __iter__() method or the __getitem__() method.


77. Is multiple inheritances supported in Python?

Yes, Python does support multiple inheritances, which means that a subclass can inherit from multiple superclasses.


78. Is Python fully object-oriented?

Python does follow an object-oriented programming paradigm and has all the basic OOPs concepts such as inheritance, polymorphism, and more, with the exception of access specifiers. Python doesn’t support strong encapsulation (adding a private keyword before data members). Although, it has a convention that can be used for data hiding, i.e., prefixing a data member with two underscores.


79. Which of the following is an invalid statement?

  1. xyz = 1,000,000

  2. x y z = 1000 2000 3000

  3. x,y,z = 1000, 2000, 3000

  4. x_y_z = 1,000,000

Ans. b statement is invalid.

80. How will you remove duplicate elements from a list?


To remove duplicate elements from the list we use the set() function.


Consider the below example:


demo_list=[5,4,4,6,8,12,12,1,5]

unique_list = list(set(demo_list))

output:[1,5,6,8,12]


81. How will you convert a string to all lowercase?

you can convert a string to all lowercase using the lower() method. This method returns a new string with all the characters in the original string converted to lowercase.


82. How can you generate random numbers in Python?

To generate random numbers in Python, you can use the random module. This module provides a variety of functions for generating random numbers and choosing random elements from sequences.


import random

x = random.random()

print(x) # prints a random float between 0 and 1


83. Why would you use NumPy arrays instead of lists in Python?


NumPy arrays provide users with three main advantages as shown below:


  1. NumPy arrays consume a lot less memory, thereby making the code more efficient.

  2. NumPy arrays execute faster and do not add heavy processing to the runtime.

  3. NumPy has a highly readable syntax, making it easy and convenient for programmers.


84. What is Polymorphism in Python?

Polymorphism is a programming concept that refers to the ability of a function or method to behave differently based on the input it receives. Polymorphism is a key feature of object-oriented programming, because it allows you to create code that is flexible and can work with multiple different types of objects.


85. What is the Python interpreter?


The Python interpreter is a software program that executes Python code. It reads Python code, translates it into machine code, and runs the machine code to produce the desired output.


86. What is the use of indentation in Python?


Indentation is used to indicate which statements belong to a block of code (such as a for loop or an if statement). Python doesn't use curly braces to indicate blocks of code like other languages, so indentation is used instead. It is important for Python code to be indented, as improper indentation can lead to errors.


87. What is the purpose of the 'except' statement in Python?


The except statement in Python is used to handle exceptions, which are runtime errors that occur during the execution of a program. When an exception occurs, the normal flow of execution is interrupted, and the Python interpreter looks for an except block that is capable of handling the exception.


  • How do you debug Python code?

  • There are several ways to debug Python code:

  • Print Statement

  • Python debugger(pdb)

  • Integrated development environments (IDEs)

  • Assertions


88. What is a lambda function?

A lambda function is an anonymous function in Python, meaning it is a function that does not have a name. Lambda functions are used to simplify the creation of small, one-time and anonymous functions. They are also known as "anonymous functions" because they are not declared in the usual way by using the def keyword.


89. What is the syntax for creating a function in Python?

The syntax for creating a function in Python is:


def function_name(parameters):

# function body

# ...

return value


90. What is the purpose of the 'else' clause in a for loop?

The 'else' clause in a for loop is used to specify a block of code to be executed when the loop terminates normally, i.e., when the loop encounters a break statement or when the condition becomes false.


91. What is the difference between shallow and deep copy in Python?

Shallow copy is a bit-wise copy of an object, which means that any changes made to the copy will affect the original object. Deep copy is a recursive copy of an object, which means that changes made to the copy do not affect the original object.


92. What is the difference between a list and a set in Python?

The main difference between a list and a set in Python is that a list is ordered and can contain duplicate elements, while a set is unordered and cannot contain duplicate elements. Additionally, lists are mutable, while sets are immutable.


93. What is a decorator in Python and how do you use it?


A decorator is a design pattern in Python that allows a user to add new functionality to an existing object without modifying its structure. Decorators are used to "decorate" a function or method by wrapping it in another function or method.


94. How do you handle exceptions in Python?


To handle exceptions in Python, you can use the try and except statements. The try block contains code that may throw an exception, and the except block contains code that will be executed if an exception is thrown.


95. What is the purpose of the del keyword in Python?

The del keyword is used to delete objects, such as variables, lists, or dictionary elements, from memory. It is also used to delete entire objects, such as classes and functions, from the current namespace.


96. How do you read and write files in Python?

n Python, you can read and write files using the built-in open() function. This function returns a file object, which you can use to read or write to the file.


97. What is the Python Standard Library?

The Python Standard Library is a collection of modules that provide access to system functionality and support common programming tasks such as file I/O, string manipulation, networking, and data types. It is an essential component of the Python language and is included in all versions of Python.


98. Define encapsulation in Python?

In Python, encapsulation refers to the idea of bundling data and methods that operate on that data within a single unit, or object. This is an important principle in object-oriented programming, as it allows you to hide implementation details and expose a clean and simple interface to users of your code.


99. What is self in Python?

In Python, self is a keyword used to refer to the instance of the class it is used in. It is used to access instance variables and methods of the class.


100. What is the difference between append() and extend() methods?

In Python, the list.append() method is used to add an element to the end of a list. It takes a single argument, which can be any value, and appends it to the list. The list.extend() method, on the other hand, is used to add multiple elements to the end of a list. It takes an iterable object, such as a list or a string, and adds each element of the iterable to the list.


101. How is Multithreading achieved in Python?

Multithreading is achieved through the threading module. This module provides a Thread class to create and manage threads.


102. What are Python libraries?

Python libraries are collections of pre-written code that you can use to perform a variety of tasks in your Python programs. They can save you time and effort by providing functionality that you can use without having to write it yourself.


103. What is the difference between .py and .pyc files?

A .py file is the source code of a Python program, while a .pyc file is a compiled bytecode version of the same program. The .pyc file is created when the program is compiled and can be executed directly.


104. What do you understand by the term namespace in Python?

Namespace in Python is a naming system used to make sure that names are unique and can be used without any conflict. It is a container used to hold a set of identifiers and names. Namespaces ensure that all the names in a program are unique and can be used without any conflict.


105. Define slicing in Python?

In Python, slicing is a feature that allows you to access a subsequence of a sequence (such as a string, tuple, or list) by specifying a range of indices. It is a convenient way to extract a portion of a sequence, or to modify a sequence by replacing or deleting a slice.


106. What is the difference between range & xrange?

In Python 2, the range function returns a list of integers, while the xrange function returns an object that generates the integers on the fly. This means that xrange is more memory-efficient than range if you are working with large sequences of numbers, because it does not create the entire list in memory at once.



Python Pseudocodes –


107.Code -

from random import shuffle

List = ['He', 'Loves', 'To', 'Code', 'In', 'Python']

shuffle(List)

print(List)


Output –

['Python', 'He', 'In', 'Code', 'Loves', 'To']



108. How will you remove duplicate elements from a list using a function?


To remove duplicate elements from the list we use the set() function.

Code –

demo_list=[1,2,3,4,5,1,2,1,3,6,7,8,9,4,7,8]

unique_list = list(set(demo_list))

print(unique_list)


Output –

[1, 2, 3, 4, 5, 6, 7, 8, 9]



109. What would be the output if I run the following code block?

list1 = [2, 33, 222, 14, 25]

print(list1[-2])


Output –

14



110. Write a code to reverse a list

my_list = [1, 2, 3, 4, 5]

my_list.reverse()

print(my_list)


Output –

[5, 4, 3, 2, 1]



111. How is an empty class created in python?


Code –

class EmptyClass:

pass

obj = EmptyClass()

obj.name = "CipherSchools"

print("Name created = ",obj.name)



Output –

Name created = CipherSchools


112. Find the output of the following code –

print("Cipher", end = "@")

print('C', 'I', 'P', 'H', 'E', 'R', sep="#")


Output –

Cipher@C#I#P#H#E#R



113. Write a Python program to display the calendar.


Code -

import calendar

year = int(input("Enter the year: "))

month = int(input("Enter the month: "))

print(calendar.month(year,month))


Output –


Enter the year: 2022 Enter the month: 10 October 2022 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31



114. How to convert tuple out of a list?


Code –

month = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']

converting_list = tuple(month)

print(converting_list)

print(type(converting_list))


Output –

('jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec')

<class 'tuple'>



115. Print the summation of all the numbers from 1 to 101?


Code –

print(sum(range(1,102)))


Output –

5151



116. How does a lambda function work?


Code –

sum_ = lambda x, y, z : x + y + z

print("Sum using lambda function is: ", sum_(4, 6, 8))


Output –

Sum using lambda function is: 18



117. What is the best way to add items to a Python array?


Code –

import array

array = array.array('d', [1 , 2 ,3] )

array.append(8)

print(array)

array.extend([4,6,9])

print(array)

array.insert(2, 9)

print(array)


Output –

array('d', [1.0, 2.0, 3.0, 8.0])

array('d', [1.0, 2.0, 3.0, 8.0, 4.0, 6.0, 9.0])

array('d', [1.0, 2.0, 9.0, 3.0, 8.0, 4.0, 6.0, 9.0])



118. What is the best way to remove values from a Python array?


Code –

array = [1, 3, 8, 1, 4, 8, 2, 4]

print(array.pop())

print(array.pop(5))

array.remove(1)

print(array)


Output –

4

8

[3, 8, 1, 4, 2]



119. Find the output –

Code –

Set Integer res = 0

do

--res

display res

res++

While(res >= 0)

End do-while


Answer –

The code will run infinite number of times.



120. Find the output –

Code –

Set value = ' ' * 10;

print value

Output –

320



121. Count the number of “#” printed


Code –

For x = 0 to 8 do

For y = 0 to 6 do

display '#'

End-for

If(x = 2) then do

break

End-if

End-for


Answer –

21



122. Find the output


s1={3, 4}

s2={1, 2}

s3=set()

i=0

j=0

for i in s1:

for j in s2:

s3.add((i,j))

i+=1

j+=1

print(s3)


Options-


a. {(3, 4), (1, 2)} b. Error c. {(4, 2), (3, 1), (4, 1), (5, 2)} d. {(3, 1), (4, 2)}


123. Identify the OPP principle(s) that has/have been implemented in the code –


class Customer:

def __init__(self,cust_id, cust_name):

self.__cust_id = cust_id

self.__cust_name = cust_name

self.__bill_amount = 0.0

class RegularCustomer(Customer):

def __init__(self,cust_id, cust_name):

self.__cust_id = cust_id

self.__cust_name = cust_name

self.__bill_amount = 0.0

self.__discount = 5


Option

a. Only Encapsulation b. Only Inheritance c. Both Encapsulation and Inheritance d. Only Polymorphism


124. Find the output –


values = ["823", "863"]

num = values[0][0:]

for row in range(0,len(values)):

for column in range(0, len(values[row])):

if num > values[row][column:]:

num = values[row][column:]

print(num)


Option –

a. 2 b. 3 c. 23 d. 823


125. Find the output –


class stud:

'Base class for all students'

def __init__(self, roll_no, grade):

self.roll_no = roll_no

self.grade = grade

def display (self):

print("Roll no : ", self.roll_no, ", Grade: ", self.grade)

print(stud.__doc__)


Option –

a. Exception is thrown b. __main__ c. Nothing is displayed d. Base class for all students


126. Consider the following algorithm of bubble sort, What will be the content of input_list after third pass ?


def bubble_sort(input_list):

num = len(input_list)

for index1 in range(num):

for index2 in range(0, num-index1-1):

if input_list[index2] > input_list[index2+1]:

input_list[index2], input_list[index2+1] = input_list[index2+1], input_list[index2]

input_list = [4,10,2,7,1,8]

bubble_sort(input_list)



Options -

a. [2,4,1,7,8,10]

b. [2,1,4,7,8,10]

c. [2,4,8,7,1,10]

d. [1,2,4,7,8,10]



6,894 views

Comentários


Subscribe to Our Newsletter

Thanks for submitting!

bottom of page