VACANCY CONNECT

Touchpad Computer Book Class 8 Ch 9 solution

Table of Contents

Touchpad Computer Book Class 8 Ch 9 solution

Touchpad Computer Book Class 8 Ch 9 Exercise Solution

Functions and String in Python

Touchpad Computer Book Class 8 Ch 9 solution

Touchpad Computer Book Class 8 Ch 9 SolutionTouchpad Computer Book Class 8 Ch 9 solution

Functions and String in Python

Click Here for free Basic Computer Knowledge

Touchpad Computer Book Class 8 Ch 9 solution

Touchpad Computer Book Class 8 Ch 8 solution

Touchpad Computer Book Class 8 Ch 9 solution

1. Tick the correct option.

a. Which type of function is append() ?

(1) Built-in

(ii) User-defined

(iii) Not a valid function

(iv) None of these

Ans: Built-in

b. What is the input given to the functions referred to as?

(1) Return Value

(ii) Name

(iii) Arguments

(iv) None of these

Ans: Arguments

c. Which user-defined function takes parameters and returns output?

(i) type 1

(ii) type 2

(iii) type 3

(iv) None of these

Ans: type3

d. Which of the following is used to insert special characters that are invalid in Python?

(i) Escape sequence

(ii) Strings

(iv) None of these

(iii) Lists

Ans: Escape sequence

e. Which operator is used to repeat the string for a given number of times?

(i) String Concatenation Operator

(ii) String Replication Operator

(iii) len()

(iv) None of these

Ans: String Replication Operator

2. Fill in the blanks using the words from the help box.

Function, append, string, lower

a. The __append___ function inserts the object passed to it at the end of the list.

b. __Function__ can be defined as a block of a reusable code that performs a specific task.

c. The _lower__ function converts all uppercase letters to lowercase.

d. A consecutive sequence of characters which are enclosed or surrounded by single or double quotes is known as a _string_.

3. Short answer type questions.

a. What are functions?

Ans: Functions are the block of organized and reusable code used to perform a single or related action. Functions receive date in the form of arguments and use it to run a specified set of statements an produce the final output.

b. Define strings.

Ans: A sequence of characters which is enclosed or surrounded by single (‘ ‘) or double (” “) quotes is known as a string. The sequence may include a letter, number, special characters or a backslash.

c. Write any two features of functions.

Ans: 1. We can call a function an many times as required.

2. Dividing a bigger program into smaller functions makes the program more manageable.

4. Long answer type questions.
a. Write the components of a function.
Ans: 1. Name of the function:
2. Arguments:
3. Statement:
4. Return Value:
b. How can we call a function in Python? Explain using an example.
Ans: We can call a function any time from other functions or from the command prompt after the definition. for calling a function, we type the function and pass the parameters. for example:
To call a function.
def my_function():                     ———> Name of a function
      print (“Hello”)                       ———> Body of a function
my_function()                             ———> Function Call
Example: #Function Example
def hello(name):
       print(“Helloo ” + name + ” ! How do you you ?”)
#Calling Function by passing parameter
hello(‘orange’)
c. What are the different types of functions. Explain in details.
Ans: There are two types of functions:
Built-In-Functions:.
Built-in-functions do not require to be written by us. 
User-Defined Functions:
user-defined function has to be developed by the user at the time of writing program.
d. Write the any two built-in-functions to manipulate strings.
Ans: 1. lower() : The lower() function converts all uppercase letters to lowercase. Syntax of using lower() function is:
string_name.lower()
2. upper() : The upper() function converts all lowercase letters to uppercase. syntax of using upper() function is 
string_name.upper()
 
Let’s Solve
Q.1 

test_str = “Good Morning” # Fix: Added missing assignment

print(“The original string is: ” + str(test_str))

hlf_idx = len(test_str) // 2 # Fix: Corrected the variable name and added missing division operator

res = “” # Fix: Initialized ‘res’ variable

for idx in range(len(test_str)):
if idx >= hlf_idx: # Fix: Corrected the comparison operator
res += test_str[idx].upper()
else:
res += test_str[idx].lower() # Fix: Changed to lowercase for the first half

print(“The resultant string: ” + str(res))

Ans: The original string is: Good Morning
          The resultant string: good MORNING
Q2 

def countX(lst, X): # Fix: Corrected variable names and removed typos
count = 0
for ele in lst: # Fix: Corrected variable name
if ele == X: # Fix: Corrected the comparison operator
count += 1
return count

lst = [5.24, 89, 5, 14, 5] # Fix: Corrected variable name

X = 5

print(“The value {} has occurred {} times”.format(X, countX(lst, X))) # Fix: Corrected formatting

Ans: The value 5 has occurred 2 times
Tech Practice

1. write a program that counts the total number of digits in the number 542892 and display it as output

Ans.

number = 542892
digit_count = len(str(number))

print(“The total number of digits in {} is: {}”.format(number, digit_count))

Output: The total number of digits in 542892 is: 6


2 type your name in python and make the first and the last letter of your nae uppercase and let the other letters remain lowercase.

Ans:

name = “OpenAI”
modified_name = name[0].upper() + name[1:-1].lower() + name[-1].upper()

print(“Original name:”, name)
print(“Modified name:”, modified_name)

Output: Original name: OpenAI
              Modified name: OpenaI

Click Here for Touchpad Computer Book Class 8  Ch 1 Solution

Click Here for Touchpad Computer Book Class 8 Ch 2 Solution

Click Here for Touchpad Computer Book Class 8 Ch 3 Solution
Click Here for Touchpad Computer Book Class 8 Ch 4 Solution
Click Here for Touchpad Computer Book Class 8 Ch 5 Solution
Click Here for Touchpad Computer Book Class 8 Ch 7 Solution
 

If you have any Query then comment

Touchpad Computer Book Class 8 Ch 7 solution

Touchpad Computer Book Class 7 Solution

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top