0% found this document useful (0 votes)
4 views2 pages

Practical Task 8

The document outlines a series of tasks for Grade 8 students at Merryland International School, focusing on user-defined functions in Python. It includes examples of functions without arguments, with arguments, with return values, and with both arguments and return values, specifically for calculating the area of a rectangle. Additionally, it presents a challenge task to create a salary calculator function that computes salary based on various inputs.

Uploaded by

sinhamanasvi26
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)
4 views2 pages

Practical Task 8

The document outlines a series of tasks for Grade 8 students at Merryland International School, focusing on user-defined functions in Python. It includes examples of functions without arguments, with arguments, with return values, and with both arguments and return values, specifically for calculating the area of a rectangle. Additionally, it presents a challenge task to create a salary calculator function that computes salary based on various inputs.

Uploaded by

sinhamanasvi26
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

Merryland International School

Department of Computer Science


TERM 3
Grade -8
UNIT -5 Python and software development
Types of user defined functions
Task 8
Name: _____________________ Sec: _______ Date: __________

TASK 8A – Functions without arguments and return values


Write a program to calculate the area of a rectangle.

Code :

def print_area():
length = 5 # Fixed value
breadth = 3 # Fixed value
area = length * breadth
print("The area of the rectangle:", area)
# Calling the function
print_area()

Outtput:
…………………………………………………………………………………………………………

In the above code, the function uses predefined values for ………………….. and
………………………………. It calculates and prints the …………………………………...

TASK 8B – Functions with arguments


Write a program to calculate the area of a rectangle with arguments.

CODE:

def area_with_arguments(length, breadth):


area = length * breadth
print("The area of the rectangle:", area)

# Calling the function with arguments


area_with_arguments(5, 3)

Outtput:
…………………………………………………………………………………………………………

Here, the function accepts values for length and breadth as ……………………………., making it more
flexible to use with …………………………….

TASK 8C – Functions with return values


Write a program to calculate the area of a rectangle with return values.
Code :

def calculate_area():
length = 5 # Fixed value
breadth = 3 # Fixed value
area = length * breadth
return area

# Calling the function and printing the result


result = calculate_area()
print("The area of the rectangle:", result)

Outtput:
…………………………………………………………………………………………………………

In the above example, the ………………………………………………. function calculates the area and
returns the ……………………………. The returned value is stored in the …………………………………..
and can be used ……………………………………………. in the main program.

TASK 8D – Functions with both arguments and return values


The following program calculates the area of a rectangle using a function with arguments and return value.

CODE:

def calculate_area(length, breadth):


area = length * breadth
return area

# Calling the function and printing the result


result = calculate_area(5, 3)
print("The area of the rectangle:", result)

Outtput:
…………………………………………………………………………………………………………

This example demonstrates how the function takes input values for length and breadth. It calculates and
returns the area. The returned value is stored in the variable result.

This type of function is highly ……………………………………………, as it can accept


…………………………………inputs and return outputs for further processing.

Challenge Task:

Salary calculator
Write a function calculate_salary() that takes the base salary, performance bonus, and extra
hours worked as arguments and returns the calculated salary. The rate for extra hours worked is
£20 per hour.

You might also like