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.
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))
The resultant string: good MORNING
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
If you have any Query then comment
More Jobs
- HPSC PGT Online Form 2024
- Class 7 Science Term Test I
- Class 6 Science Paper Term I
- Andhra Pradesh Teacher Eligibility Test (APTET) July 2024
- Vacancy Connect Online Tuition Classes
- Music Online Tuition Classes
- Mathematics Online Tuition Classes
- Social Studies Online Tuition Classes
- Computer Science Online Tuition Classes
- Science Online Tuition Classes