Python Programming Assignment-1
Instructions For Writing*
❖ Write on A4 size pages
❖ Hand-written only, in clear and neat handwriting
❖ Bind pages in a proper stick file
Sample Handwritten Assignment Front Page Layout
❖ [Institute/University Name]
❖ Department of Computer Science & Engineering
❖ Assignment Title: Python Programming
❖ Course Name & Code: B.Tech CSE – CS-601
❖ Student Name: [Kunal Maurya]
❖ Roll Number: [Your Roll Number]
❖ Semester & Year: [e.g., 6th Semester, 2025]
❖ Submitted to: [Faculty Name, Designation]
❖ Deadline for Submission: 19-08- 2025 (without fail)
❖ Date of Submission: [Actual Date You Submit]
To solve all the questions are mandatory*
----------------------------------------------------------------------------------------------------------------
Q1: Write a Python program that accepts user input for name, age, and marks in three subjects.
Display the output in a formatted string. Explain the role of type() and is operator in your code.
Q2: Write a Python program to accept the following inputs from the user:
• Name (string)
• Age (integer)
• Height (float)
Display the output in a formatted sentence using the print() function. Explain the role of type
conversion in your program.
Q3: Design a Python program that:
• Reads a string input from the user
• Checks if the string is a valid identifier using the isidentifier() method
• Displays whether the string is a valid Python identifier or not
Explain the rules for creating valid identifiers in Python.
Q4: Create a Python script that demonstrates the use of:
• Identifiers and keywords
• Variables and data types
• Operators (arithmetic, relational, logical)
Include examples for each and explain the concept of precedence and associativity.
Q5: Design a Python function that calculates the factorial of a number using both for and while
loops. Include input validation using if...else statements and demonstrate the use of default
parameters and scope of variables.
Q6: Create a Python function that checks whether a number is prime. Use if, elif, and else
statements along with a for loop. Include:
• A default parameter
• A return statement
• Explanation of variable scope and lifetime
Q7. Write a Python script that:
• Takes a sentence as input
• Counts the number of vowels and consonants
• Converts the sentence to uppercase and lowercase
• Reverses the sentence using slicing
Formats the output using string methods Explain the use of indexing and slicing in your
solution.
Q8: Write a Python program to manage a student list. Include operations to:
• Add new students
• Remove students
• Sort the list alphabetically
• Display the list using slicing
Use built-in list functions and explain the difference between indexing and slicing, the role of
the del statement.
Q9. Create a Python program that:
• Stores student data (name, roll number, marks) using a dictionary
• Uses a tuple to store subject names
• Converts dictionary keys into a set and performs union and intersection operations with
another set
Explain the relationship between tuples, lists, and dictionaries. Demonstrate the use of the
zip() function and set methods.
Q10. Write a Python program to perform the following tasks:
1. Create a dictionary to store employee details (name, ID, department).
2. Add at least five employee records to the dictionary.
3. Use a for loop to display all employee details.
4. Update the department of a specific employee using their ID.
5. Convert the dictionary keys into a tuple and demonstrate tuple slicing.
Explain the use of dictionary methods, tuple operations, and the relationship between
dictionaries and tuples in your solution.