Python Practical Assignment 3.1

Write a Python Function to Take Name & Roll No. as Arguments and Pass the Values

Introduction

In Python, a function is used to perform a specific task. We can pass values like name and roll number as arguments to a function and display them.


Logic to Write the Code

  1. Start the program.
  2. Define a function with two parameters (name and roll number).
  3. Inside the function, print the received values.
  4. Call the function and pass the name and roll number.
  5. End the program.

Source Code (Beginner Friendly)

# Python function to take name and roll number as arguments

# Defining the function
def student_details(name, roll_no):
    print("Student Name:", name)
    print("Roll Number:", roll_no)

# Calling the function and passing values
student_details("Avi", 101)

Sample Output

Student Name: Avi
Roll Number: 101

Viva Questions with Answers

1. What is a function in Python?

A function is a block of code that performs a specific task.

2. What are arguments in a function?

Arguments are the values passed to a function when it is called.

3. How do you define a function in Python?

By using the def keyword.
Example: def function_name():

4. Can we pass multiple arguments to a function?

Yes, we can pass multiple arguments separated by commas.

5. Is it necessary to pass values in the same order as parameters?

Yes, values should be passed in the same order unless using keyword arguments.


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top