0% found this document useful (0 votes)
2 views

String_FunctionsTypes_of_Data_and_Types_of_Errors copy

The document outlines learning objectives for developing text-based programs using string manipulation, including functions for length, upper case, and lower case. It emphasizes the importance of applying test plans with normal, extreme, and invalid data, as well as identifying various types of errors such as syntax, logic, and runtime errors. Additionally, it provides examples of string operations and error handling in Python programming.

Uploaded by

zoeadler1910
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

String_FunctionsTypes_of_Data_and_Types_of_Errors copy

The document outlines learning objectives for developing text-based programs using string manipulation, including functions for length, upper case, and lower case. It emphasizes the importance of applying test plans with normal, extreme, and invalid data, as well as identifying various types of errors such as syntax, logic, and runtime errors. Additionally, it provides examples of string operations and error handling in Python programming.

Uploaded by

zoeadler1910
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Learning Objectives:

1. Know how to develop text-based programs using string manipulation, including length, upper case,
and lower case.
2. Know how to develop and apply test plans that include normal, extreme and invalid data.
3. Identify test data that covers normal, extreme and invalid.
4. Identify a range of errors, including syntax, logic, and runtime errors.

Know how to develop text-based programs using string manipulation, including length, upper case, and
lower case.
word1 = "programming"
word2 = "MANIPULATION"

Why do you need to change any words entered into a computer?

• to access only certain characters


• to split an address
• to check what has been entered.

Why would you need to find out how many letters were in a word?

Answer: To make sure it was the correct length, to check if a word is entered.

for example:
word1 = "PROGRAMMING"
word2 = "MaNiPuLaTiOn"
word3 = "eNCRYPTION"
word4 = "network"

• Output the length of the string in word1


Solution: print(len(word1))
• Convert word2 to lowercase and store it back in the variable word2
Solution: word2 = word2.lower()
• Store the length of word3 in a variable
Solution: length = len(word3)
• Convert word3 to uppercase and output the result
Solution: print(word3.upper())
• Find and output the longest word
Solution:
length1 = len(word1)
length2 = len(word2)
length3 = len(word3)
length4 = len(word4)
if(length1 > length2 and length1 > length3 and length1 < length4):
print(word1)
elif(length2 > length3 and length2 > length4):
print(word2)
elif(length3 > length4):
print(word3)
else:
print(word4)

Combine strings with an array, for example:


wordArray = ["house", "car", "balloon", "greenhouse"]

To output the length of each word in the array. The solution is:
for x in range(0, 4):
print(len(wordArray[x]))

What does the function ‘length’ do?

Answer: It returns the length of the string.

What does the function ‘lower’ do?

Answer: It returns the string in lower case.

What does the function ‘upper’ do?

Answer: It returns the string in upper case.

What would you do to find the length of a string?

Answer: Use the function len

How would you find the shortest word?

Answer: Find the length of each word and then use an if statement to compare them.

How would you check if the word a user has entered is long enough?
Answer: Find the length of the word and use an if statement to compare it to the minimum length.

String Funtion Purpose

lower() Converts a string into lower case

Upper() Converts a string into upper case

Len() Finds the length of the string

Know how to develop and apply test plans that include normal, extreme and invalid data.

Identify test data that covers normal, extreme and invalid.

In order to determine whether a solution is working as it should, it needs to be tested.

Usually before a whole system is tested each sub-system is tested separately. Computer programs can be
tested by running them on a computer using any data that is required and seeing what result is output.
However, in order to test a solution thoroughly it may need to be worked through several times with
different sets of test data. A set of test data is all the items of data required to work through a solution.
Identify a range of errors, including syntax, logic, and runtime errors.

An error just means that a program doesn't work as intended, also called a bug.

Syntax errors

A syntax error means that a program is not valid Python. It doesn't abide by the official rules of the Python
language, just like "eat potato good" does not abide by the official rules of the English language.

Common syntax errors include mismatched parentheses, mismatched string quotation marks, and invalid
indentation.
Runtime errors

he computer only discovers these errors as it's running the program, hence the name RUN-time. The
program is valid Python syntax, but when the computer actually tries to execute a particular instruction, it
gets confused.

With runtime errors, the computer executes all the lines of code before the incorrect line. If these lines
print values, we see their output appear in the console. The computer only reports an error when it
reaches the incorrect line. Then, it terminates the program. It does not execute any remaining lines of
code.

Logic errors

Logic errors are a mismatch between what the programmer intended and what the code they wrote
actually does. To the computer, these programs seem totally fine. There's nothing wrong with the Python
syntax and it understands all of the instructions. When it runs the program, it executes successfully; there
is no error message.

This can make logic errors challenging to spot, because the computer can't offer any help here. The
programmer has to identify why the result they're getting isn't quite right.

You might also like