0% found this document useful (0 votes)
3 views3 pages

Assignment

The document contains a series of programming assignment questions and code snippets related to string manipulation in Python. It includes examples of string slicing, immutability, error handling, and basic string operations such as checking for palindromes and counting vowels. Additionally, it highlights common errors and their corrections in Python code.

Uploaded by

skyhawker130
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Assignment

The document contains a series of programming assignment questions and code snippets related to string manipulation in Python. It includes examples of string slicing, immutability, error handling, and basic string operations such as checking for palindromes and counting vowels. Additionally, it highlights common errors and their corrections in Python code.

Uploaded by

skyhawker130
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ASSIGNMENT

1.c) String
2.b) yth
3.d) len()
4. b) Hello
5. b) False
6. b) *
7. a) AAA
8. c) -1
9. d) All of these
10. c) len(S) - 1
11.
s = "Informatics Practices"
print(s[-9:-1])
Output: Practice
12.
txt = "welcome to python"
x = [Link]()
print(x[1])
Output:
to
13.
str1 = "Aman"
str2 = "Aman"
print(str1 is str2, str1 == str2)
Output:
True
14.
word = "Amazing"
print(word[1:6:2])
Output:
mzn

18.
Str = "Global Warming"
Str[3] = 'p'
print(Str)
Error: Strings are immutable, characters cannot be changed
directly.
Type of Error: TypeError

17.
val = "1234"
if [Link]:
print(val + 1)
else:
print("Not a number")
Errors:
1. isnumeric should be called → [Link]()
2. val is a string → cannot add integer directly
Correct version:
if [Link]():
print(int(val) + 1)
18.
s = input("Enter a string: ")
count = 0
for ch in [Link]():
if ch in "aeiou":
count += 1
print("Number of vowels:", count)

19.
s = input("Enter a string: ")
if s == s[::-1]:
print("Palindrome")
else:
print("Not a Palindrome")

20.
s = input("Enter a sentence: ")
print([Link]())

You might also like