Python Programming
Class Assessment # 1
Duration: 60 Minutes
Total Questions: 5
Total Marks: 50
Question 1: User Greeting and Age Check (10 Marks)
Task:
Write a Python program that:
1. Asks the user to input their name and age.
2. Prints a greeting using the name.
3. If the user is 18 or older, print: "You are eligible to vote."
4. If the user is younger than 18, print: "You are not eligible to vote."
Sample Output:
Enter your name: Sara
Enter your age: 20
Hello, Sara!
You are eligible to vote.
Question 2: Sum of Even Numbers (10 Marks)
Task:
Write a Python program that:
1. Asks the user to input a positive integer n.
2. Uses a for loop to calculate the sum of all even numbers from 1 to n.
3. Prints the result.
Sample Output:
Enter a positive integer: 10
The sum of even numbers from 1 to 10 is 30.
Question 3: Star Pattern Generator (10 Marks)
Task:
Write a Python program that:
1. Asks the user to input a number n.
2. Uses a for loop to print a right-angled triangle pattern with n rows made of stars
(*).
3. Each row should contain that many stars as the row number.
Sample Output (if n = 5):
*
**
***
****
*****
Question 4: Extract Information from a Formatted String (10 Marks)
Task:
Write a Python program that:
1. Asks the user to input a string in the following format:
name=Ali;age=20;city=Lahore
2. Extracts the name, age, and city from the string.
3. Assigns them to separate variables and prints each one clearly.
Requirements:
• Use string manipulation methods such as split() and indexing to extract data.
• Do not use external libraries like re.
Sample Output:
Enter the string: name=Ali;age=20;city=Lahore
Name: Ali
Age: 20
City: Lahore
Question 5: Student Marks Report (10 Marks)
Task:
You are asked to write a Python program for a school to generate a simple student
report. The
program should:
1. Ask the user how many students' data they want to enter.
2. For each student:
• Ask for the student's name.
• Ask for the student's marks out of 100.
• Print whether the student has Passed (marks >= 50) or Failed (marks < 50).
3. After all entries, print the total number of students who passed and failed.
Sample Output:
How many students? 3
Enter name of student 1: Ali
Enter marks of Ali: 78
Ali has Passed.
Enter name of student 2: Zara
Enter marks of Zara: 45
Zara has Failed.
Enter name of student 3: Imran
Enter marks of Imran: 66
Imran has Passed.
Total Passed: 2
Total Failed: 1