0% found this document useful (0 votes)
5 views7 pages

Solution (Computer) Chap 7, 8, 9

The document covers Python control flow statements, lists, and data visualization. It includes exercises with fill-in-the-blanks, multiple-choice questions, and programming tasks related to these topics. Key concepts such as sequential statements, conditional statements, looping, list methods, and data visualization techniques using Matplotlib are discussed.
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)
5 views7 pages

Solution (Computer) Chap 7, 8, 9

The document covers Python control flow statements, lists, and data visualization. It includes exercises with fill-in-the-blanks, multiple-choice questions, and programming tasks related to these topics. Key concepts such as sequential statements, conditional statements, looping, list methods, and data visualization techniques using Matplotlib are discussed.
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

CLASS – VIII

SUBJECT – COMPUTER
Chapter – 7 | PYTHON-CONTROL OF FLOW STATEMENTS
SOLVED EXERCISE

A. Fill in the blanks. B. Tick () the right answer. C. Write true (T) or false (F).
1. decisions, execution 1. (c) if-elif-else 1. True
2. sequential 2. (c) if 2. False
3. conditional 3. (c) Multiple times 3. False
4. Loop 4. (b) for 4. True
5. else: 5. (b) range() 5. True

D. Answer the following questions. (Page No. 100)


Q.1. What do you mean by control of flow statements?
Ans. Control of flow statements refers to the structures in programming that allow you to
control the order in which instructions are executed.

Q.2. Write a short note on sequential statement.


Ans. A sequential statement in programming refers to a line of code or instruction that is executed
one after the other in a specific order.

Q.3. Write a short note on conditional statement.


Ans. A conditional statement in programming allows for the execution of different blocks of
code based on certain conditions.

Q.4. Define looping statement with an example.


Ans. Looping statements are executed sequentially the first statement in a block is executed first,
followed by the second, and so on. A looping statement allows you to execute a statement or
group of statements multiple times.
Example: Do yourself. (You can do)

Q.5. Write down the difference between if-else and if-elif.


Ans. if-else: provides a way to make decisions and control the flow of program by providing
alternative paths of execution.
If-elif: in programming allows for the execution of different blocks of code vbased on
multiple conditions.

E. Answer below following deepen your understanding. (Page No. 101)


Q.1. Write a short note on for loop. Explain with an example.
Ans. For loop is used to repeat itself over a range of values or a sequence. It executed for each of
these items in a range. These values can be numeric, string, list, tuple. Statements of for loop
executes several times until the given condition becomes false.
Example: for i in range(1, 5):
print(i)

Page 1 of 7
Q.2. Create a program in PYTHON to accept month number from the user & display month
name (for ex. If user enters 1, is should display January)
Ans. m = int(input('Enter the month no.: '))
if m==1:
print('January')
elif m==2:
print('February')
elif m==3:
print('March')
elif m==4:
print('April')
elif m==5:
print('May')
elif m==6:
print('June')
elif m==7:
print('July')
elif m==8:
print('August')
elif m==9:
print('September')
elif m==10:
print('October')
elif m==11:
print('November')
elif m==12:
print('December')
else:
print('Invalid option')

Q.3. Create a program in PYTHON to accept a year from the user & check it is leap year or
not.
Ans. y = int(input('Enter any year: '))
if y%4 == 0:
print('Leap Year')
else:
print('Not a Leap Year')

Q.4. Create a program in PYTHON to display sum of first 10 numbers.


Ans. sum = 0
for i in range(1, 11):
sum = sum + i
print('Sum of first 10 nos.: ', sum)

Page 2 of 7
Q.5. Create a program in PYTHON to display series from 20 to 15.
Ans. print('Displaying series from 20 to 15')
for i in range(20, 14, -1):
print(i)

End of Chapter-7 (PYTHON-CONTROL OF FLOW STATEMENTS)

Page 3 of 7
Chapter – 8 | LIST IN PYTHON
SOLVED EXERCISE

A. Fill in the blanks. B. Tick () the right answer. C. Write true (T) or false (F).
1. square bracket [ ] 1. (a) index number, element 1. True
2. [:] 2. (a) first 2. True
3. + 3. (b) pop( ) 3. False
4. error 4. (d) remove( ) 4. False
5. append( ) 5. (c) reverse 5. False

D. Answer the following questions. (Page No. 115)


Q.1. Write a short note on list.
Ans. A list I a collection of values or items. The items in a list can be of any type such as string,
integers, floats or even lists.

Q.2. Explain the different methods through which list can be created.
Ans. The different methods through which list can be created are: -
1. Lists can be created by putting comma separate values within square brackets.
2. The list() method in Python takes sequence types and converts a given record/string into
list.

Q.3. What do you mean by traversing? Explain with an example.


Ans. Traversing means accessing each elements of a list. You can use for or while loop to
traverse a list. It can be done by using two ways:
Example:
Using ‘IN’ operator Using ‘RANGE()’ function
list1=[10, 20, „Bye‟] list1 = [10, 20, „Bye‟]
for i in list1: a=len(list1)
print(i) for i in range(a:
print(list1[i])

Q.4. What membership testing?


Ans. You can check whether a particular item is a member of specified list or not using ‘in’ or ‘not
in’ operator.

Q.5. What do you mean by slicing? Explain with suitable example.


Ans. Slicing is used to retrieve a subset of values.
Example:
Program Output
list1=[10,20,30,„Hello‟,50.5,60] [20, 30, „Hello‟]
print(list1[1:4])
list1=[10,20,30,„Hello‟,50.5,60] [20, „Hello‟, 60]
print(list1[1:6:2])

Page 4 of 7
E. Answer the following questions. (Page No. 116)
Q.1. Write down the difference between append() and extend() function.
Ans. append(): append() method adds a single item to the end of the list. It doesn’t create a new
list.
extend(): extend() method adds one list at the end of another list. In other words, all
elements of a list are added at the end of an already existing lsit.

Q.2. What do you mean by sorting? Explain different method to sort list items in ascending
and descending order.
Ans. Sorting means sorts the items in a list, by default ascending order. For descending order, we
have to reverse function along with sort function.
Example (ascending order) Output
odd = [1,9,7,3,5,7,4,7]
[Link]()
print(odd) [1,3,4,5,7,7,7,9]
Example (descending order) Output
odd = [1,9,7,3,5,7,4,7]
[Link](reverse=True)
print(odd) [9,7,7,7,5,4,3,1]

Q.3. Which method is used to count how many times an Item appear in the list? Given
example.
Ans. It counts how many times an item appears in the list.
Example (count() method) Output
odd = [1,9,7,3,5,7,4,7]
c=[Link]()
print(c) 3

Q.4. Write short note on pop() method.


Ans. pop() method removes an element from the given index and also returns the deleted
element.
Example (pop() method) Output
List1 = [1,3,5,7,8,6,5,4]
a=[Link](1)
print(a) 3
print(List1) [1,5,7,8,6,5,4]

Q.5. Write a short note on remove() method.


Ans. remove() method is used when we know the element to be deleted from the list and not the
index.
Example (remove() method) Output
List1=[1,3,5,7,8,6,5,4]
print(List1)
[Link](6) [1,3,5,7,8,5,4]

End of Chapter-8 (LIST IN PYTHON)

Page 5 of 7
Chapter – 9 | DATA VISUALIZATION IN PYTHON
SOLVED EXERCISE

A. Fill in the blanks. B. Tick () the right answer. C. Write true (T) or false (F).
1. quantitative 1. (a) plot() 1. True
2. Matplotlib 2. (c) Both a and b 2. False
3. pip install matplotlib 3. (b) 0.8 3. True
4. title() 4. (b) barh() 4. True
5. savefig() 5. (a) pie() 5. False

D. Answer the following questions. (Page No. 124)


Q.1. What is Data Visualization?
Ans. Data visualization is the graphical representation of information and data i.e. it presents
quantitative information in a graphical form.

Q.2. Write a short note on matplotlib.


Ans. Matplotlib is an visualization library in Python for 2D plots of arrays. It is a multi-platform
data visualization library. It was introduced by John Hunter in 2002.

Q.3. Write down the steps for plotting a graph.


Ans. 1. Import [Link]
2. Choose the appropriate plot type like line, bar, pie, etc.
3. Create a list of values according to the type of plot chosen.
4. Use the built-in functions to set various parameters and to view the plot.

Q.4. Write a short note on line plot.


Ans. Line plot is the most common, simplest and classic type of plot.
It shows a change in one or more variables over time.
The plot() method is used to plot the line.

Q.5. Write down the names of different parameters that can be used with line chart.
Ans.
Parameter Purpose
linewidth To set the width of the line
lindstyle To set line style
marker To set a symbol that represents a data value
color To specify the color of the line

E. Answer the following questions. (Page No. 125)


Q.1. Write a short note on bar plot.
Ans. 1. Bar plot presents data in the form of bars with height and lengths.
2. Bar plots are used to compare multiple variables in a single timeframe or a single variable
in a time series.

Q.2. Write a short note on pie plot.


Ans. 1. Pie chart can display only one series of data.
2. It’s in the form of circle which is divided into sectors to illustrate numerical proportion.

Page 6 of 7
Q.3. Explain various parameters that can be used bar graph.
Ans.
Parameter Purpose
Width To set width of the bar, default width is 0.8
Color To specify the color of the bar

Q.4. Write down the purpose of pie plot.


Ans. The purpose is used to graph qualitative data, where the information describes a trait or
attribute and is not numerical.

Q.5. Write down the code to display name and marks of four students in the form of line
graph. (You can assume your own data for this)
Ans. import [Link] as plt
name=[“Aman”, “Ram”, “Shyam”, “Mohan”]
marks=[40, 35, 37, 25]
[Link](name, marks)
[Link]()

End of Chapter-9 (DATA VISUALIZATION IN PYTHON)

---THE END---

Page 7 of 7

You might also like