std-8

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

NextGen International Coding and Engineering

(NICE) School & College


Worksheet
Class: STD-VIII
Student’s Name: Subject: Python Programming Language Date: 21.04.24

Teacher’s Name: Jahanara Taznina Orin Roll: Submission date: 22.04.24

Q1. Rewrite the following code in Python after removing all errors to get the correct output.
Code:
a. number = int(Input("Enter the value of number:")
if number % 2 == 0 and number % 5 == 0:
print("The number is divisible by both 2 and 5.")
elif number % 2 = 0:
print("The number is divisible by 2 but not by 5.")
elif number % 5 == 0
print(The number is divisible by 5 but not by 2.)
els:
print("The number is neither divisible by 2 nor by 5.")
Correct code:

Output:

b.Code:
weather="raining"
if weather="sunny":
print("wear sunblock")
elif weather="snow":
print("Going skiing")
else:
print("None of the above")
Correct code:
Output:

Q 2: Correct the following program to print the following pattern.


Code:
rows = 7
for i in range(3, rows + 1):
print("+" * i)
Output:
*
**
***
****
*****
Correct Code:

Q3: Sort the given programs:


a. Code:
Perimeter= 2*(Length+Width)
Length=int(input("Enter the the value of Length:"))
Area=Length*Width
print("Perimeter of a Rectangle:", Perimeter)
print("Area of a Rectangle:", Area)
Width=int(input("Enter the the value of Width:"))
Correct Code:
Output:

b. Code:
print("Perimeter of a Triangle :", Perimeter)
Area=1/2*(Base* Height)
Side2=int(input("Enter the value of Side2:"))
Base=int(input("Enter the value of Base:"))
Height=int(input("Enter the value of Height:"))
Side1=int(input("Enter the value of Side1:"))
print("Area of a Triangle :", Area)
Side3=int(input("Enter the value of Side3:"))
Perimeter= Side1+Side2+Side3
Correct Code:

Output:
NextGen International Coding and Engineering
(NICE) School & College
Worksheet
Class: STD-VIII
Student’s Name: Subject: Python Programming Language Date: 22.04.24

Teacher’s Name: Jahanara Taznina Orin Roll: Submission date:

Write programs with output:


1. Write a Python program to print each item in the sequence until you reach the end of the given list: fruits = ["apple",
"kiwi", "banana", "pears"]
2. Write a program to print a multiplication table of a given number-“6”
3. Conditional Statements Please write Python Programs for all the problems. Take a variable ‘age’ which is of positive
value and check the following:
a. If the age is less than 10, print “Children”.
b. If the age is more than 60, print ‘senior citizens’
c. If it is between 10 and 60, print ‘normal citizen’
4. Write a Python program to check whether the given number is divisible by 2,5 or not 2,5.
Q. The following questions require you to trace the behavior of some Python code and identify the output of that code.
question, write the output for the code
segment in the box provided.
Q. Fix the given code to get the following output:
Output:
Name : Amrit Code:
Your Score
Math : 85
C.S. : 60
Name : tanmay
Your Score
Math : 60
C.S. : 85
Name : jay
Your Score
Math : 85
C.S. : 36

Correct code:
Q. The following are true/false questions. Write either ‘T’ or ‘F’ in the boxes at the bottom of the page. If there’s
any counter-example, it’s false.
(a) A function must always have a return statement.

(b) Functions in Python can accept multiple arguments, separated by commas when called.

(c) print() is an example of a user-defined function.

(d) A function created by the user for its own program requirements is called a built-in function.

(e) We don’t need to write a code for the library function.

(f) Default arguments in a function automatically take a default value when no value is specified in the

function call.
(g) When passing a mutable object to a function in Python, the function can modify the object.

(h) A variable, with a global scope can’t be used anywhere in the program.

(i) A variable declared inside the function's body scope is known as a local variable.

(j) In Python, Functions can return only single values using the return statement.

a b c d e f g h i j

You might also like