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

Python_Questions_Solutions

The document contains a series of Python programming questions along with their solutions. Each question focuses on a specific programming task, such as string manipulation, list operations, and dictionary handling. The solutions are provided in Python code format, demonstrating practical applications of programming concepts.

Uploaded by

rajpoots13209
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python_Questions_Solutions

The document contains a series of Python programming questions along with their solutions. Each question focuses on a specific programming task, such as string manipulation, list operations, and dictionary handling. The solutions are provided in Python code format, demonstrating practical applications of programming concepts.

Uploaded by

rajpoots13209
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Programming Questions and Solutions

1) W.A.P to enter your school's name & print your school name up to 8th character n times.
```python
school_name = input("Enter your school's name: ")
n = int(input("Enter n: "))
print((school_name[:8] + '\n') * n)
```

2) W.A.P to calculate the total number of characters, digits, and spaces in a string.
```python
text = input("Enter a string: ")
characters = sum(c.isalpha() for c in text)
digits = sum(c.isdigit() for c in text)
spaces = sum(c.isspace() for c in text)
print(f"Characters: {characters}, Digits: {digits}, Spaces: {spaces}")
```

3) W.A.P to find whether two strings contain the same number of characters or not.
```python
str1 = input("Enter first string: ")
str2 = input("Enter second string: ")
print("Equal length" if len(str1) == len(str2) else "Not equal length")
```

4) W.A.P to print a string list in reverse order.


```python
string_list = input("Enter a list of strings separated by space: ").split()
print(list(reversed(string_list)))
```

5) W.A.P to take any message as input & print it without vowel characters.
```python
message = input("Enter a message: ")
vowels = "AEIOUaeiou"
print("".join(c for c in message if c not in vowels))
```

6) W.A.P to delete all the odd numbers & negative numbers in a numeric list.
```python
nums = list(map(int, input("Enter numbers separated by space: ").split()))
filtered_nums = [num for num in nums if num % 2 == 0 and num >= 0]
print(filtered_nums)
```

7) W.A.P to delete all duplicates from the given list.


```python
lst = [12, 12, 34, 34, 56, 11, 32, 32, 11, 10, 10]
lst = list(set(lst))
print(lst)
```

8) W.A.P to copy dictionary items.


```python
dict1 = {"a": 1, "b": 2, "c": 3}
dict2 = dict1.copy()
print(dict2)
```

9) W.A.P to change dictionary items.


```python
dictionary = {"name": "Alice", "age": 25}
dictionary["age"] = 30
print(dictionary)
```

10) W.A.P to convert the first letter of a sentence into capital.


```python
sentence = input("Enter a sentence: ")
print(sentence.capitalize())
```

11) W.A.P to create a dictionary from a string (track the count of the letters).
```python
text = "w3resource"
letter_count = {char: text.count(char) for char in set(text)}
print(letter_count)
```

12) W.A.P to find the second highest value in a string.


```python
s = input("Enter a string with numbers: ")
numbers = sorted(set(int(c) for c in s if c.isdigit()), reverse=True)
print(numbers[1] if len(numbers) > 1 else "Not enough unique numbers")
```

13) W.A.P to read a list and remove duplicates, keeping only unique elements.
```python
lst = list(map(int, input("Enter numbers separated by space: ").split()))
unique_lst = list(set(lst))
print(unique_lst)
```

14) W.A.P to find the number of times an element occurs in a list.


```python
lst = list(map(int, input("Enter numbers separated by space: ").split()))
element = int(input("Enter element to count: "))
print(lst.count(element))
```

You might also like