Python Assignment 1
Q1. Number Pattern Pyramid
Write a program that takes an integer `n` from the user and prints a pyramid pattern of numbers
like this:
Enter number of rows: 4
1
23
456
7 8 9 10
Use nested loops and ensure proper spacing.
Q2. Vowel & Consonant Counter
Read a string `s` from the user. Write a program that counts and prints the number of vowels (a,
e, i, o, u – case insensitive) and consonants in the string.
Handle spaces and punctuation marks by ignoring them.
Example:
Enter a string: Hello World!
Vowels: 3
Consonants: 7
[Link] a list of integers `nums`, perform the following operations:
1. Create a new list `even_nums` containing only the even numbers from `nums`.
2. Square each number in `even_nums`.
3. Print the sum of the squared numbers.
Input format:
Enter numbers separated by space: 1 2 3 4 5 6
Output:
Sum of squares of even numbers: 56 (i.e., 2² + 4² + 6² = 4 + 16 + 36 = 56)
Q4. Write a program that reads student data in the following format:
- Input: Number of students `n`
- For each student, read `name`, `marks` (out of 100) in a line separated by comma (e.g.,
`Alice,85`).
Compute the grade using the following criteria:
- 90 ≤ marks ≤ 100 → A
- 80 ≤ marks < 90 → B
- 70 ≤ marks < 80 → C
- 60 ≤ marks < 70 → D
- marks < 60 → F
Store the result in a dictionary where the key is the student name and the value is the grade.
Finally, print the dictionary.
Example:
Enter number of students: 3
Enter details (name,marks): Alice,92
Enter details (name,marks): Bob,78
Enter details (name,marks): Carol,65
Output: {'Alice': 'A', 'Bob': 'C', 'Carol': 'D'}