0% found this document useful (0 votes)
14 views4 pages

Unit1,2 2marks Answers

Uploaded by

adobemonish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views4 pages

Unit1,2 2marks Answers

Uploaded by

adobemonish
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

GE3151- PROBLEM SOLVING AND PYTHON PROGRAMMING

Unit 1- COMPUTATIONAL THINKING AND PROBLEM SOLVING


PART-A(2MARKS)
1. Define algorithm. List the guidelines for writing algorithm.
Algorithm is an ordered sequence of finite, well defined, unambiguous instructions
for completing a task. It is a step- by-step procedure for solving a task or a problem.
Guidelines for writing algorithm:
▪ An algorithm should be clear, precise and well defined.
▪ It should always begin with the word start and end with the word stop.
▪ Each step should be written in a separate line.
▪ Steps should be numbered as step1,step2 and so on
2. What are the properties of algorithm?
Finiteness, definiteness, input, output, Effectiveness
3. List the different building blocks of algorithms.
❖ Statements
❖ State
❖ Control flow statements (Sequence, Selection, Repetition)
❖ Functions
4. Define Control flow statement with an example.
▪ Sequential – sequence of statements is executed one after another in same order
▪ Selection - used for decisions and branching
▪ Repetition - used for looping, i.e., repeating a piece of code multiple times.
5. Limitations of flowchart?
Complex, oversimplifying, repeated modifications and reproduction
6. Define recursive function.
A function that calls itself during its execution, Recursive functions are made up of two
parts: the base case and the recursive case. The base case is the condition that stops the
recursion, and the recursive case is where the function calls itself.

7. Define an iterative statement.


An iterative statement, also known as a loop, is a statement that repeatedly executes a set
of instructions until a condition is met
8. What are the types of computation problems?
four types of computational problems: decision problems, search problems, optimization
problems, and counting problems.
9. Write an algorithm to accept two numbers, compute the sum and print the result.
Step 1: Start
Step 2: Read two numbers from A and B from user
Step 3: Assign sum=0
Step 4: Calculate sum=A+B
Step 5: Print sum
Step 6: stop
10. Draw a flowchart to find the maximum among the three numbers.

11. Develop an algorithm to convert Temperature in Celsius to Fahrenheit and vice versa.
Celsius to Fahrenheit
Step 1: start
Step 2: Identify the temperature value in Celsius.
Step 3: Multiply the given temperature by 9.
Step 4: Divide the product by 5.
Step 5: Add 32 to the result of Step 3. That will be the required value in degree Fahrenheit (°F) =
(C*9 /5) + 32.
Step 6: stop
Fahrenheit to Celsius :
Step 1:start
Step 2:Read the temperature in Fahrenheit
Step 3:Subtract 32 from the Fahrenheit temperature
Step 4:Multiply the result by five
Step 5:Divide the result by nine
Step 6:Print the temperature in Celsius C = 5/9(F-32)
Step 7: stop
12. Differentiate user defined function and pre-defined function.
User-Defined Functions: User-defined functions are custom procedures that users program
and implement in their software. ...
Built in Functions: Built-in functions in Python are pre-defined functions that can be used
without additional code.
13. What are all the key steps performed in algorithmic problem solving?
Step 1: Obtain a description of problem
Step 2: Analyze the problem
Step 3: Develop a high-level algorithm
Step 4: Refine the algorithm by adding more details.
Step 5: Review the algorithm
Unit 2 – DATA TYPES, EXPRESSIONS, STATEMENTS
PART-A(2MARKS)
1. Name five primitive data types in python?

2. What is debugging?
Debugging is the process of identifying and fixing errors in a program.
Categorized:
(i) Syntax errors
(ii) Logical errors
(iii) Runtime errors
3. What are keywords and give some examples?
Keywords in Python are reserved words that cannot be used as a variable name, function name,
or any other identifier.
Example: True, False, else, import, break, if, is, continue, except, finally, pass, raise, return, try,
while, def, del, elif,for
4. Differentiate between interactive mode and script mode.

5. What is indentation?
Python indentation refers to adding white space before a statement to a particular block of
code. In other words, all the statements with the same space to the left, belong to the same
code block
Example:
6. Identify the operand(s) and operator(s) in the following expression: Sum = a + b
Operands are: sum, a ,b
Operators are: = , +
7. List out the rules to be followed in naming variable.
• The first character of the variable must be an alphabet or underscore ( _ )
Ex: name
_ name
• Name must not contain any white space or special character (! , @ , # , % , ^ , & , *)
Ex : !name
First name
last@name
• Name must not be similar to any keywords defined in the language.
• Variable names are case sensitive. Example: name , NAME
8. Write a snippet to display “Hello World” in Python Interpreter.
>>> print(“Hello world”)
>>> Hello world
9. Illustrate the use of * and + operators in string with example.
Concatenation(+):
The joining of two or more strings is called concatenation. The plus (+) operator is used to
concatenate strings in python.
Example:
>>> “welcome”+”python”
welcomepython

Repetition (*):
The multiplication opeartor(*) is used to display a string multiple times.
Example:
>>> str1=”welcome sundhari”
>>> Print(str1*2)
welcome sundhari welcome sundhari
10. How do you assign a value to a tuple in Python.?
Tuples are created by placing a sequence of values separated by commas within parenthesis
( ). Once a tuple is created, cannot change its values. Tuples are unchangeable, or immutable.
(=) symbol assigns the value on the right to the name on the left.
Example:
days = ("monday",”Tuesday”,”Wednesday”,”Thursday”,”Friday”,”Saturday”,”Sunday”)
11. Write a python program to slicing in string?
name = "Hello, World!"
print(name[:])
print(name[1:])
print(name[1:5])
output: Hello world
ello world
ello

12. What does immutable mean; which data type in python are immutable?
Immutable means not changing, or unable to be changed (for example, by adding new
elements, removing elements, or replacing elements).
Immutable data types: Strings, Tuple,sets

You might also like