Indexing, Slicing and Iteration
Task 1
Take a string from the user and reverse print it using loop (not slicing), with-
a) Positive indexing
b) Negative indexing
Sample Input Output
Hello olleH
olleH
Task 2
Take a string from the user and print the last 3 characters using-
a) Positive indexing
b) Negative indexing
[Assume the length of the string is at least 3]
Sample Input Output
Hello llo
llo
Task 3
Take a string from the user and reverse print the last 3 characters using-
a) Positive indexing
b) Negative indexing
[Assume the length of the string is at least 3]
Sample Input Output
Hello oll
oll
Task 4
Take a string from the user and print the first 3 characters using slicing with-
a) Positive indexing
b) Negative indexing
[Assume the length of the string is at least 3]
Sample Input Output
Hello Hel
Hel
Task 5
Take a string from the user and reverse print the first 3 characters using slicing with-
a) Positive indexing
b) Negative indexing
[Assume the length of the string is at least 3]
Sample Input Output
Hello leH
leH
Ascii Conversion and Vowel-Consonant
Task 6
Take a string from the user check whether it contains at least:
1 upper-case, 1 lower-case, 2 digits and 1 of these special characters: @, #, %, *, &, ! _
• If it does not contain any of the criteria, print which is missing.
• If it satisfies all the condition, print valid password.
Sample Input #1: Sample Input #2:
Hello Kitty Daddy21$$
Output: Output:
Digit missing Valid password
Special character missing
Task 7
Take a string from the user print how many vowels and consonants it contains.
Sample Input:
Nourin619Fizza
Output:
Vowels: 5
Consonants: 6
Task 8
Take a string from the use and print an updated string based on the following conditions:
• Convert all the lowercase alphabets to their previous corresponding upper-case letters.
• Convert all the upper-case alphabets to their next corresponding lower-case letters.
• Keep the digits and special cases unchanged
• Ignore spaces
Sample Input #1: Sample Input #2: Sample Input #3:
Abc 123$ Zz 1 3 # aA
Output: Output: Output:
bAB123$ aY13# Zb
Task 9
Take a string from the user and print whether if it is a palindrome or not.
Sample Input #1 Sample Input #2 Sample Input #3
MURDERREDRUM RACECAR KANANAZIF
Output: Output: Output:
Palindrome Palindrome Not Palindrome
Tracing
Task 10
Trace the following code, show tracing table and write the outputs:
sinthia= 21.619 Output
print(int(sinthia))
print(sinthia//10)
sinthia*=-1
print(int(sinthia))
print(sinthia//10)
sinthia*=-1
sinthia-=0.619
print(sinthia==21)
tahmid=str(int(sinthia))
print(tahmid==21)
for faiza in tahmid:
print(faiza)
for fairuz in range(0, len(tahmid),1):
print(fairuz)
for mia in range(0,len(tahmid),1):
print(tahmid[mia])
print(float(tahmid [0: len(tahmid):1])== str(21.0))
Task 11
x=0 Output
y=0
z=15
a = '21<-69'
while x< 5:
z -= 1
y=z
while y > 10:
if y % 2 == 0:
a += '->'
a = a + str(x) + str(y // 2)
else:
a = '<-'
a = a + str(x // 2) + str(y)
print(a)
y-=1
x+=1