Programs are a set of instructions given to the computer to solve a problem.
A/An Algorithm is defined as a finite sequence of steps required to get the desired output.
A Flowchart is a type of diagram that represents the algorithm graphically using boxes of various types, connected by arrows.
Python was created by Guido Van Rossum.
Python is called a/an interpreted language.
Python syntax is Case-Sensitive.
In Python, a syntax error is detected by the interpreter at runtime.
Python is a/an platform independent language.
To start Python from the command prompt, use the python command.
Python programs are saved using the .py or .pyw extension.
Python programming can be done in interactive and script modes.
There are no standard rules to write Pseudocode.
An Algorithm is the process to write step-wise solution of a given problem in English-like language.
Decomposition is the process of breaking down a complex problem into smaller problems so that they can be managed easily.
print() is defined as an output statement to display the result of a code on the output screen.
Breaking down a complex problem into smaller parts is called decomposition.
Answer
True
Reason — Decomposition is the process of breaking down a complex problem or system into smaller, easily manageable parts.
Pseudocode is the pictorial representation of an algorithm.
Answer
False
Reason — Flowchart is the pictorial representation of step-by-step solution to a given problem. While, pseudocode is a simple and informal way of writing programming code in English.
Python is a dynamically typed language.
Answer
True
Reason — Python is a dynamically typed language because variables do not need to be declared with a specific type. Instead, the type of a variable is determined at runtime based on the value assigned to it.
Alt+R is used to repeat the last typed command in Python shell.
Answer
False
Reason — For repeating or recalling the last command in the Python shell, the correct key is the up arrow key (↑).
Print and print are same in Python.
Answer
False
Reason — In Python, print and Print are not the same because Python is a case-sensitive language.
The sep argument is used with print() method.
Answer
True
Reason — The sep
argument in the print()
function is used to specify a string that separates the objects being printed. The default separator is a space.
Python is a compiled high-level language.
Answer
False
Reason — Python is an interpreted high-level language.
Python is a cross-platform language.
Answer
True
Reason — Python is a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux, etc.
The default extension of Python program file is *.pyt.
Answer
False
Reason — The default extension of Python program file is .py or .pyw.
Python Editor refers to Script mode in Python.
Answer
True
Reason — Python Editor refers to a mode in IDLE where we can write and run Python scripts, also known as Script mode.
Ctrl+Q shortcut key combination is used to exit Python.
Answer
True
Reason — Ctrl+Q shortcut key combination is used to exit Python.
Python code can run on a variety of platforms.
Answer
True
Reason — Python is platform independent and can run across different operating systems/platforms like Windows, Linux/Unix, macOS and other operating Systems.
A rectangle represents a process in a flow chart diagram.
Answer
True
Reason — In a flowchart diagram, a rectangle is used to represent a process step.
What is an algorithm?
- A set of steps to solve a problem
- Software that analyzes data
- A hardware device that stores data
- All of these
Answer
A set of steps to solve a problem
Reason — A finite sequence of steps required to get the desired output is called an algorithm.
What shape represents a decision in a flow chart?
- Diamond
- Rectangle
- Oval
- Parallelogram
Answer
Diamond
Reason — Diamond represents decision/condition in a flow chart.
Python was developed by ............... .
- Charles Babbage
- Guido van Rossum
- Tim Berners Lee
- Robert E. Kahn
Answer
Guido van Rossum
Reason — Python was developed by Guido van Rossum.
You don't have to pay for Python and you can view its source code too. It means Python is-
- Freeware
- Free and Open source
- Open source
- Shareware
Answer
Free and Open source
Reason — Python is both free and open-source, meaning it is available for free and its source code can be viewed, modified, and distributed by anyone.
Identify the correct print() statement:
- print(Hello)
- print("Hello")
- print('Hello")
- print("Hello')
Answer
print("Hello")
Reason — In Python, when using the print()
function, strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct statement is print("Hello")
.
Python is a/an ............... language.
- Compiled
- Interpreted
- Compiled & Interpreted
- None of these
Answer
Interpreted
Reason — Python is an interpreted language. This means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.
The interactive interpreter of Python is termed as ............... .
- Python shell
- Python Script mode
- Python Editor mode
- Python command line
Answer
Python shell
Reason — The interactive interpreter of Python is termed as Python shell.
The three greater than signs (>>>) are called the Python ............... .
- Cursor
- Command prompt
- Pointer
- Blinking cursor
Answer
Command prompt
Reason — The three greater than signs (>>>) are called the Python command prompt or interactive prompt.
Which of the following codes is correct?
1.
print("Programming is fun")
print("Python")
print("Computer Science")
2.
print ("Programming is fun)
print("Python")
print("Computer Science)
3.
Print("Programming is fun")
print("Python")
print("Computer Science")
4.
Print("Programming is fun")
Print("Python")
Print("Computer Science")
Answer
print("Programming is fun")
print("Python")
print("Computer Science")
Reason — In Python, the print()
function is written in lowercase (print) and strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct code would be :
print("Programming is fun")
print("Python")
print("Computer Science")
Python is a case-sensitive language. This means ............... .
- Capital and small letters are same for Python
- Python doesn't care about the case of alphabets
- Python treats capital and small letters as different
- Python automatically capitalizes the small letters
Answer
Python treats capital and small letters as different
Reason — Python is a case-sensitive language. This means that Python differentiates between capital and small alphabets.
For which set of values will the Python code (s = (a**4) + 5*5**(b + b)) give the output as: 141?
- a = 1, b = 2
- a = 3, b = 2
- a = 2, b = 1
- a = 3, b = 1
Answer
a = 2, b = 1
Reason — For a=2, b=1:
s = (24) + 5 * (52) = 16 + 5*25 = 16 + 125 = 141
............... mode of Python gives instant result of typed statement.
- Interactive mode
- Script mode
- Both Interactive and Script mode
- None of these
Answer
Interactive mode
Reason — Interactive mode of Python gives instant result of typed statement.
Assertion (A): Python is a cross-platform language.
Reasoning (R): Python code can run on a variety of platforms which makes programs very portable as any program written in one platform can easily be used on another.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
Python is a cross-platform language, meaning it is platform-independent and can run across different operating systems such as Windows, Linux/Unix, macOS, and others. Python's ability to execute on various platforms enhances the portability of its programs, allowing the same code to be used across different environments without modification.
Assertion (A): Python comes with its own IDLE.
Reasoning (R): IDLE is Python's Integrated Development and Learning Environment which allows programmers to easily write, modify and execute Python programs.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
Python comes with its own IDLE, which is included with Python installations. IDLE is a simple Integrated Development and Learning Environment; it is a program that allows the user to edit, run, browse and debug a Python program from a single interface.
Assertion (A): The interactive mode of Python gives instant result of the typed statement.
Reasoning (R): Script mode is an interactive window where Python code can be executed in the same window.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
A is true but R is false.
Explanation
The interactive mode of Python gives instant results for typed statements. The Python Shell is an interactive window where you can type in Python code and see the output immediately in the same window. It serves as an interface between Python commands and the operating system.
Assertion (A): Python uses an interpreter to convert source code to object code.
Reasoning (R): Python interpreter scans and translates the whole program into machine code in one go.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
A is true but R is false.
Explanation
Python uses an interpreter to convert source code into object code. The Python interpreter does not scan and translate the whole program into machine code in one go. Instead, it interprets the code line by line, converting each line into machine code and executing it immediately.
Assertion (A): To print the value of a variable, Python uses print() method.
Reasoning (R): print() method displays the content on the system screen or console.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
The print()
function is a built-in function in Python that displays the content on the system screen or console. To print the value of a variable, Python uses the print()
function.
Assertion (A): The shortcut key to run a Python program from script mode is F1.
Reasoning (R): Python programs/scripts are stored in files with .py extension.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
A is false but R is true.
Explanation
The shortcut key to run a Python program from script mode is F5. Python programs/scripts are stored in files with .py or .pyw extension.
Assertion (A): Python is the fastest language.
Reasoning (R): Python is an interpreted language.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
A is false but R is true.
Explanation
Python is not considered the fastest programming language as it is slower than many compiled languages such as C or C++ because it is interpreted rather than compiled. Python is an interpreted language, which means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.
Assertion (A): Python is a case-sensitive language.
Reasoning (R): Python is easy to understand as it has a clearly defined syntax and simple structure.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true but R is not the correct explanation of A.
Explanation
Python is a case-sensitive language. This means that Python differentiates between capital and small alphabets. Python programs use clear, simple, concise instructions and clearly defined syntax and simple structure that are easy to read and understand even by non-programmers.
Python is free and open-source. What do you understand by this feature?
Answer
Python is free and open-source means that it is available to anyone at no cost, and its source code can be freely accessed, modified, and distributed by anyone.
Write some limitations of Python.
Answer
Some limitations of Python programming language are:
- Not the Fastest Language — As Python is an interpreted language so its execution-times are not that fast compared to some compiled languages.
- Lesser Libraries than C, Java, Perl — Library collection of C, Java, Perl is better than Python.
- Not strong on Type-Binding — Python interpreter is not very strong on catching 'Type-Mismatch' issues.
- Not easily convertible — Translating Python programs to other languages is difficult due to its lack of syntax.
What is the difference between Script mode and Interactive mode in Python?
Answer
In script mode, we write a Python program in a file and execute it to display the output and in interactive mode, we use the Python prompt '>>>' to start typing commands and see immediate output.
Differentiate between flow chart and algorithm.
Answer
Flow chart | Algorithm |
---|---|
A flow chart is defined as a visual representation of the sequence of steps and decisions needed to perform a process/task. | A finite sequence of steps required to get the desired output is called an algorithm. |
In the flowchart, symbols/shapes are used. | In the algorithm, plain text is used. |
Write a pseudocode that reads two numbers and divide one by another and display the quotient.
Answer
Step 1: INPUT num1
Step 2: INPUT num2
Step 3: IF num2 == 0 THEN
Step 4: PRINT "Error: Division by zero is not allowed."
ELSE
Step 5: COMPUTE quotient = num1 / num2
Step 6: PRINT quotient
Two friends decide who gets the last slice of a cake by flipping a coin five times. The first person to win three flips wins the cake. An input of 1 means player 1 wins a flip, and a 2 means player 2 wins a flip. Design an algorithm to determine who takes the cake?
Answer
Step 1: Initialize Counters:
SET p1 = 0
SET p2 = 0
Step 2: Process Coin Flips:
FOR each flip from 1 to 5
INPUT result
IF result is 1 THEN
INCREMENT p1
ELSE IF result is 2 THEN
INCREMENT p2
IF p1 is 3 THEN
PRINT "Player 1 wins the cake."
EXIT the algorithm
ELSE IF p2 is 3 THEN
PRINT "Player 2 wins the cake."
EXIT the algorithm
Write a pseudocode to print all multiples of 5 between 10 and 25 (including both 10 and 25).
Answer
Step 1: SET start = 10
Step 2: SET end = 25
Step 3: FOR num = start TO end
Step 4: IF num MOD 5 is 0 THEN
Step 5: PRINT num
Write a pseudocode that will perform the following:
(a) Read the marks of three subjects: Computer Science, Mathematics and Physics out of 100.
(b) Calculate the aggregate marks.
(c) Calculate the percentage of marks.
Answer
Step 1: Input the marks in Computer Science
Step 2: Input the marks in Mathematics
Step 3: Input the marks in Physics
Step 4: Set total marks by adding marks in Computer Science, Mathematics and Physics
Step 6: Set percentage by dividing total marks by 300 and then multiply it by 100
Step 7: Display total marks and percentage
Write an algorithm to find the greatest among two different numbers entered by the user.
Answer
Step 1:
INPUT number1
INPUT number2
Step 2:
IF number1 > number2 THEN
PRINT "The greatest number is: " + number1
ELSE
PRINT "The greatest number is: " + number2
Step 3: END
Write an algorithm that performs the following:
Ask a user to enter a number.
If the number is between 5 and 15, write the word GREEN.
If the number is between 15 and 25, write the word BLUE.
If the number is between 25 and 35, write the word ORANGE.
If it is any other number, write that ALL COLORS ARE BEAUTIFUL.
Answer
Step 1: INPUT number
Step 2:
IF number is between 5 and 15 THEN
PRINT "GREEN"
ELSE IF number is between 15 and 25 THEN
PRINT "BLUE"
ELSE IF number is between 25 and 35 THEN
PRINT "ORANGE"
ELSE
PRINT "ALL COLORS ARE BEAUTIFUL"
Write an algorithm that accepts four numbers as input and find the largest and smallest of them.
Answer
Step 1: INPUT num1, num2, num3, num4
Step 2: SET largest = num1
Step 3: SET smallest = num1
Step 4: IF num2 > largest THEN
Step 5: SET largest = num2
ELSE IF num2 < smallest THEN
Step 6: SET smallest = num2
Step 7: IF num3 > largest THEN
Step 8: SET largest = num3
ELSE IF num3 < smallest THEN
Step 9: SET smallest = num3
Step 10: IF num4 > largest THEN
Step 11: SET largest = num4
ELSE IF num4 < smallest THEN
Step 12: SET smallest = num4
Step 13: PRINT "The largest number is: " + largest
Step 14: PRINT "The smallest number is: " + smallest
"Decomposition leads to simplicity." How?
Answer
Decomposition is the process of breaking down a complex problem or system into smaller, easily manageable parts. These smaller problems are solved one after the other until the bigger complex problem is resolved. This stage involves breaking down the problem into smaller components so that they can be tackled more easily. The more we can break down a problem, the easier it is to solve.
Write an algorithm to find a factorial of an inputted number.
Answer
Step 1: Start
Step 2: Input the number "n" from the user.
Step 3: Initialize a variable "fact" to 1.
Step 4: If n is 0, then the factorial is 1 and go to Step 7.
Step 5: If "n" is greater than 0, multiply "fact" by each integer from 1 to "n" in sequence.
Step 6: The final value of "fact" is the result.
Step 7: Display "fact".
Step 8: End
Match the pairs:
Answer
The matched pairs are given below:
Write the pseudocode to print the bill depending upon the price and quantity of an item. Also, print Bill GST, which is the bill after adding 5% tax in the total bill.
Answer
Step 1: INPUT price
Step 2: INPUT quantity
Step 3: COMPUTE total_bill = price * quantity
Step 4: COMPUTE gst_amount = total_bill * 0.05
Step 5: COMPUTE bill_with_gst = total_bill + gst_amount
Step 6: PRINT "Total Bill: ₹" + total_bill
Step 7: PRINT "Bill with GST: ₹" + bill_with_gst
When was Python released?
Answer
Python was released in February 1991.
Who developed Python and which two languages contributed to Python as a programming language?
Answer
Guido Van Rossum is the developer of Python. ABC language and Modula-3 contributed to Python as a programming language.
Is Python case-sensitive?
Answer
Yes, Python is a case-sensitive language. This means that Python differentiates between uppercase (capital) and lowercase (small) letters.
What is IDLE?
Answer
IDLE is a simple Integrated Development and Learning Environment that comes with Python. The most important feature of IDLE is that it is a program that allows the user to edit, run, browse and debug a Python program from a single interface.
Differentiate between displaying and printing method in Python.
Answer
Printing in Python refers to using the print()
function to output information to the console. The print()
function takes one or more arguments, converts each argument to a string (if necessary), and displays them as text. On the other hand, displaying can be a more general term that encompasses presenting information or output in various forms, not limited to just text output in the console.
Briefly explain the salient features of Python.
Answer
The salient features of Python are as follows:
- Python is an interpreted, interactive, directly executed language with a pre-compiled code. This means that it is processed at runtime by the interpreter and we need not compile our program before executing it.
- It is a loosely type object-oriented programming language with a few keywords, simple English-like structure and is easy to learn.
- It is a free, open-source and portable language having a large repository of libraries.
- It takes less time to develop as Python programs are typically 3 to 5 times shorter than the equivalent programming languages. This is because of its built-in, high-level data types and its dynamic typing.
- It is extensible/extendable and highly efficient as there is no wastage of time in declaring the types of variables or arguments.
- It supports GUI (Graphical User Interface) and garbage collection (better memory management).
- It is easily compatible with other languages like C, C++, Core Java etc.
- Python is used for both scientific and non-scientific programming.
What do you understand by cross-platform software with respect to Python?
Answer
Python is platform-independent and a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux etc.
What are the advantages of Python programming language?
Answer
Advantages of Python programming language are:
- Easy to Use — Python is compact, programmer-friendly and very easy to use object oriented language with very simple syntax rules.
- Expressive Language — Python is an expressive language, it takes fewer lines of codes to represent the same syntax.
- Interpreted Language — Python is an interpreted language, not a compiled language. It makes Python an easy-to-debug language and thus suitable for beginners to advanced users.
- Completeness — Python has a rich standard library that provides modules for most types of required functionality like emails, web-pages, databases, GUI development, network connections, etc.
- Cross-platform Language — Python can run equally well on variety of platforms — Windows, Linux/UNIX, Macintosh, supercomputers, smart phones, etc.
- Free and Open Source — Python language is freely available along with its source-code.
- Variety of Usage/Applications — Python has evolved into a powerful, complete and useful language over these years. These days Python is being used in many diverse fields/applications, some of which are Scripting, Web Applications, Game development, Database Applications, System Administrations, Rapid Prototyping, GUI Programs.
In how many different ways can you work in Python?
Answer
We can work in Python in two ways:
- Interactive mode (also called Immediate mode)
- Script mode
What are the advantages/disadvantages of working in Interactive mode in Python?
Answer
Interactive mode is useful for testing code. We can type the commands one by one and get the result of error immediately for each command. Disadvantages of Interactive mode are that it does not save commands in form of a program and also output is sandwiched between commands.
Write instructions to the Interactive mode for the following:
(a) To display sum of 3, 8.0, 6 * 12
(b) To print sum of 16, 5.0, 44.0
Answer
(a)
>>> 3 + 8.0 + 6 * 12
(b)
>>> print(16 + 5.0 + 44.0)
Write the given instructions in Interactive and Script modes to get the following result:
Python is easy to learn and write.
It allows us to work in two modes: Interactive mode and Script mode.
Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.
We find it interesting to work with Python.
Answer
Interactive Modes
>>> print("Python is easy to learn and write.")
>>> print("It allows us to work in two modes: Interactive mode and Script mode.")
>>> print("Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.")
>>> print("We find it interesting to work with Python.")
Script Modes
print("Python is easy to learn and write.")
print("It allows us to work in two modes: Interactive mode and Script mode.")
print("Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.")
print("We find it interesting to work with Python.")
Python is easy to learn and write.
It allows us to work in two modes: Interactive mode and Script mode.
Interactive mode is also known as Python Shell and Script mode is known as Python Editor. It is a platform-independent language.
We find it interesting to work with Python.
Write a code that prints your full name and your birthday as separate strings.
Answer
full_name = "Jeevika Sharma"
birthday = "January 17, 2000"
print("Full Name:", full_name)
print("Birthday:", birthday)
Full Name: Jeevika Sharma
Birthday: January 17, 2000
Record what happens when the following statements are executed:
(a) print (n=17)
(b) print (8 + 9)
(c) print (4.2, "hello", 6 - 2, "world", 15/2.0)
(d) print ("123abc", sep = '-')
(e) print ("XXX", end ='!')
Answer
(a) print(n=17) — It raises an error because the syntax print(n=17) is incorrect. In this context, n=17 is trying to use an argument name assignment within the print() function, which is not valid.
(b) print(8 + 9) — 17
(c) print(4.2, "hello", 6 - 2, "world", 15/2.0) — 4.2 hello 4 world 7.5
(d) print("123abc", sep = '-') — 123abc
(e) print("XXX", end ='!') — XXX!
Use IDLE to calculate:
(a) 6+4*10
(b) (6+4) *10
Answer
(a) 46
(b) 100
Try the following code on Python Shell and evaluate the output generated:
>>> print("Python is easy to learn and write.")
>>> print(3.14159*7)
>>> print('I am a class XI' + 'student')
>>> print('I', 'm')
>>> print("class XI student")
>>> print("I'm", 16, "years old")
Answer
Python is easy to learn and write.
21.99113
I am a class XIstudent
I m
class XI student
I'm 16 years old
Draw a flow chart to count and display the even and odd numbers in a given list of integers.
Answer
The flow chart is given below: