0% found this document useful (0 votes)
4 views

Assignments on Functions & Modules

The document outlines two assignments focused on functions and modules in programming. Assignment 1 includes tasks such as defining functions for greeting, arithmetic operations, and handling variable-length arguments. Assignment 2 involves creating a module for basic math operations and using built-in modules for generating random numbers, displaying the current date and time, and printing the working directory.

Uploaded by

rushikeshzore99
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 views

Assignments on Functions & Modules

The document outlines two assignments focused on functions and modules in programming. Assignment 1 includes tasks such as defining functions for greeting, arithmetic operations, and handling variable-length arguments. Assignment 2 involves creating a module for basic math operations and using built-in modules for generating random numbers, displaying the current date and time, and printing the working directory.

Uploaded by

rushikeshzore99
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
You are on page 1/ 2

Assignment 1: Functions

Basic Function Definitions

Write a function greet that takes a name as an argument and prints a greeting message.
For example, greet("Alice") should print "Hello, Alice!".

Functions with Return Values

Write a function add that takes two numbers as arguments and returns their sum.

Write a function multiply that takes two numbers as arguments and returns their
product.

Default Arguments

Write a function power that takes two arguments, base and exponent, and returns the
result of raising base to the power of exponent. The exponent should have a default
value of 2.

Keyword Arguments

Write a function introduce that takes two arguments, name and age, and prints a
message introducing the person. Use keyword arguments to call this function.

Variable-Length Arguments

Write a function average that takes any number of numerical arguments and returns
their average.

Assignment 2: Modules

Creating and Importing Modules

Create a module named math_operations.py containing the following functions:

1. add(a, b) - returns the sum of a and b.


2. subtract(a, b) - returns the difference when b is subtracted from a.
3. multiply(a, b) - returns the product of a and b.
4. divide(a, b) - returns the quotient when a is divided by b.

Create another script main.py and do the following:

1. Import the math_operations module.


2. Use the functions from the math_operations module to perform basic arithmetic
operations.
3. Print the results of these operations.
Using Built-in Modules

1. Write a script that uses the random module to generate a random integer between 1
and 100 and print it.
2. Use the datetime module to print the current date and time.
3. Use the os module to print the current working directory.

You might also like