Unit1,2 2marks Answers
Unit1,2 2marks Answers
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