ITEC-425 / SENG-425: Python Programming Lab Lab 6: Strings Task 1
ITEC-425 / SENG-425: Python Programming Lab Lab 6: Strings Task 1
Lab 6: Strings
Task 1
Write a program to calculate the length of a given message.
Note: In this case do this WITHOUT using the built-in len() function.
In [1]:
message = input("Enter a message: ")
count = 0
Task 2
Modify the above program to use a the buil-in len() function to find the length of a
message.
In [2]:
message = input("Enter a message: ")
print("The length of the message is", len(message))
Task 3
Take the following Python code that stores a string:
str_val = 'X-DSPAM-Confidence:0.8475'
Use find() function and string slicing to extract the portion of the string after the colon
character and then use the float() function to convert the extracted string into a
floating point number. Verify by checking the type of the converted number.
In [3]:
str_val = 'X-DSPAM-Confidence:0.8475'
0.8475
<class 'float'>
0.8475
Task 4
Consider the string give below, and the write python code to do the followig tasks:
str_val = 'the quick brown fox jumps over the lazy dog'
In [4]:
str_val = 'the quick brown fox jumps over the lazy dog'
Task 5
Write a program that asks the user to input a message and displays the number of words
in the message.
In [6]:
message = input("Enter your message: ")
word_count = 0
for wd in split_message:
word_count = word_count + 1
Page 2 of 3
print("Your message has", word_count, "words")
Page 3 of 3