Assignment-5
Create a notebook file yourname-rollno-string.ipynb
share the same in group.
Strings
Outcome: Learn String Indexing and slicing, programming with strings
1.Consider the string str="Python Programming by Yourname" ( Replace Yourname with your first name)
Write statements in python to implement the following and also print the output of each statement.
a) To display the last four characters.
b) To display the substring starting from index 4 and ending at index 8.
c) Find the length of the string,min and max(characters)
d) To trim the last four characters from the string.
e) To trim the first four characters from the string.
f) To display the starting index of the substring 'gr'.
g) To change the case of the given string.( small letter to capital and capital to small)
h) To check if the string is in title case.
i) To replace all the occurrences of letter 'm' in the string with '*'
j)reverse the string
k)count the occurrence of the character ‘m’
l)characters in even positions 0,2,4,…..
m) characters in even positions 0,2,4,…..in reverse order
n)check whether the substring ‘on’ is present in the string or not
o)Find the first occurrence of character ‘t’
p)convert the string into upper case
2. Write a program to check whether the given string is palindrome or not
3. Count the vowels, digits, consonents, spaces in a string.
4. Read a binary number as a string and find its corresponding decimal ( multiply with powers of 2)
i/p= 10111 o/p 23
5. Read a decimal number and find its binary.( Hint: divide by 2 and append the reminder to a string)
i/p:13 o/p: 1101
6. Read a string and print all 4 letter words.
7. Find the average word length.( find word length of each word and then find the average)
8. Read a string and swap the case ( small letters to capital letters and capital letters to small letters)
9. Encrypt a string using the shift cipher( key=3 Ceaser cipher).Encrypt your name.
10. Write a Python program to check the validity of a password given by the user.
The Password should satisfy the following criteria:
1. Contains at least one letter between a and z
2. Contains at least one number between 0 and 9
3. Contains at least one letter between A and Z
4. Contains at least one special character from $, #, @
5.Minimum length of password: 8
11. Find the decimal equivalent of a binary number i/p:1011.11 o/p :11.75
12. Read a decimal number as string find the binary Eg: i/p 12.75 o/p;1100.11
13. Input KTU ID and display the college and branch name
14.Input your phonenumber. Check the validity: must contain 10 digits, First digits must 9 or 8.No other characters allowed.
Enter the string...this is a test
new string after removing vowels= ths s tst
17.Slice the string to two separate strings; one with all the characters in the odd indices and one with all characters in even indices
18.Remove all occurrence of a substring from a string
19.Count number of letters , digits, words,uppercase and lower case letters in a string
20.Assume that the variable data refers to the string "Python rules!". Use a string method to perform the following tasks: ( University Question)
a. Obtain a list of the words in the string.
b. Convert the string to uppercase.
c. Locate the position of the string "rules" .
d. Replace the exclamation point with a question mark.
21.Convert a hexadecimal number to binary ( use a dictionary to store the hex values)
22.Count the frequency of occurance of each character in a string ( use a dictionary to store the count)
Comments
Post a Comment