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]())