Class 8 Computer Science Notes
Unit-4
"Programing"
Exercise Short Response Questions and Answers:
Q1. For the following code block sprite will turn to 30 degrees. How many clicks are required for the sprite to complete a full cycle?
Ans:
In a complete full cycle, there are 360 degrees, and 360/30 = 12. Thus 12 clicks are required for a sprite to complete a full cycle.
Q2. What is the difference in outputs of the following code blocks, having 4 backdrops?
Ans:
In this case, the sprite moves forward 10 steps delaying 0.5 seconds, and code to execute a task that is to be achieved multiple times can iteratively be embedded in a simple loop.
In this case, the sprite moves forward 10 steps and each step delaying time 0.5 seconds, and the coder to execute a task that is to be achieved multiple times can iteratively be embedded in a simple loop.
Q3. For the maze game, duplicate the 'maze map' and rename it 'maze- map2'. Next, change the color of the line in the new map from blue to red. Add scripts such that the games become a multi-level game with the 2 distinct images.
Ans:
Follow the instruction given in the question and perform the activity by using scratch programming on your computer.
What to do:
Open the Scratch program to duplicate the map maze and remain its manemap2, next, change the color of lines in the new map from blue to red. Add scripts such that the games become a multi-level game with 2 distinct images.
Follow the instruction given in the question and perform the activity by using scratch programming on your computer.
What to do:
Open the Scratch program to duplicate the map maze and remain its manemap2, next, change the color of lines in the new map from blue to red. Add scripts such that the games become a multi-level game with 2 distinct images.Q4. Take a 4-digit number as input for a year and check if the year is a leap year or not. Display your output as: the year 1979 is not a leap year or the year 2020 is a leap year.
Ans:
program:
# Python program to check if the year is a leap year or not
Year = 1979 and 2020
# To get the year (integer input) from the user
# year = int (input (“Enter a year: “))
# Divided by 100 means century year (ending with 00)
# Century year divided by 400 is a leap year
If (year % 400 == 0) and (year % 100 == 0) :
Print (“{0} is a leap year”. Format(year))
# Not divided by 100 means, not a century year
# year divided by 4 is a leap year
elif (year % 4 == 0) and (year % 100 != 0) :
Print (“{0} is a leap year”. Format(year))
# if not divided by both 400 (century year) and 4 (not century year)
# Year is not leap year
Else:
Print (“{0} is not a leap year”. Format (year))
Output:
1979 is not a leap year
2020 is a leap year
Ans:
# Python program to check if the year is a leap year or not
Year = 1979 and 2020
# To get the year (integer input) from the user
# year = int (input (“Enter a year: “))
# Divided by 100 means century year (ending with 00)
# Century year divided by 400 is a leap year
If (year % 400 == 0) and (year % 100 == 0) :
Print (“{0} is a leap year”. Format(year))
# Not divided by 100 means, not a century year
# year divided by 4 is a leap year
elif (year % 4 == 0) and (year % 100 != 0) :
Print (“{0} is a leap year”. Format(year))
# if not divided by both 400 (century year) and 4 (not century year)
# Year is not leap year
Else:
Print (“{0} is not a leap year”. Format (year))
1979 is not a leap year
2020 is a leap year
Q5. Take length and width as input from the user for a quadrilateral and check if it is a square or rectangle.
Ans:
1 class Rectangle():
2 def __init__(self, l, w):
3 self.length = l
4 self.width = w
5
6 def rectangle_area(self):
7 return self.length*self.width
8
9 newRectangle = Rectangle(12, 10)
10 print(newRectangle.rectangle_area())
Output:
Rectangle area 120
1 class Rectangle():
2 def __init__(self, l, w):
3 self.length = l
4 self.width = w
5
6 def rectangle_area(self):
7 return self.length*self.width
8
9 newRectangle = Rectangle(12, 10)
10 print(newRectangle.rectangle_area())
Output:
Rectangle area 120
Q6. Write a program in python for the following output [print a star triangle].
Ans:
Ans:
output:
* * * * * * * * * * * * * * *
output:
*
Q7. Write a program in python that display squares of the numbers and print in the form of a triangle.
Ans:
Ans:
Program:
# Python 3.x code to demonstrate number pattern
# Function to demonstrate printing pattern of numbers
def countnum(n):
#initializing starting number
Num = 1
# Outer loop to handle number of rows for i in range (0, n):
# note re assigning num
# num = 1
# inner loop to handle number of columns
# values changing according to outer loop for j in range (0, i*i):
#printing number
Print(num, end=” “)
# Incrementing number at each column
num=num*num
# ending line after each row
Print(“\r”) n=5
# sending 5 as argument
# calling function
Countnum(n)
Output:
1
4 9
16 25 36
49 64 81 100
Program:
# Function to demonstrate printing pattern of numbers
def countnum(n):
#initializing starting number
Num = 1
# Outer loop to handle number of rows for i in range (0, n):
# note re assigning num
# num = 1
# inner loop to handle number of columns
# values changing according to outer loop for j in range (0, i*i):
#printing number
Print(num, end=” “)
# Incrementing number at each column
num=num*num
# ending line after each row
Print(“\r”) n=5
# sending 5 as argument
# calling function
Countnum(n)
1
4 9
16 25 36
49 64 81 100
************************************
************************************
Shortcut Links For:
1. 5th Class All Subjects Notes
2. 8th Class All Subjects Notes
0 Comments
Start Tuition (in Pakistan or Abroad) from Experienced Online Teachers.
Contact WhatsApp for tutoring and Assignment help on +923339719149