top of page

Topic 6: Problem solving with programming

PART 3- 6.3 DATA TYPES AND STRUCTURES

On this page is:

  • Activities

  • What You Need To Know

 

 

BOOTCAMPS

Please complete these bootcamps below to become an expert in these areas:

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

DATA BOOTCAMP 6- STRINGS CHALLENGE 1

Write a program to ask the user for their full name. It should output:
a.    The whole name
b.    the first character
c.    the first 5 characters
d.    the fourth, fifth and sixth characters

Use Python on the PC or Go to this site: https://www.onlinegdb.com/online_python_compiler

GET STARTED HELP!

name=input("

print ("Your name is

print("The first character of your name is

print("The first 5 characters of your name is

print("The 4th, 5th and 6th characters of your name are

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

DATA BOOTCAMP 7- STRINGS CHALLENGE 2

a) Use Python on the PC or Go to this site: https://www.onlinegdb.com/online_python_compiler

b) Your help can be found from here

c) Create a program which asks for a name, adjective, noun, verb and adverb.

d) It will then output silly sentence back to the user, including the words input.

GET STARTED HELP!

name=input("

noun=input("

verb=input("

adverb = input("

print ("Your name is

print ("Here is a silly sentence")

print(

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

DATA BOOTCAMP 8- STRINGS CHALLENGE 3

a) Use Python on the PC or Go to this site: https://www.onlinegdb.com/online_python_compiler

b) Your help can be found from here

c) Write a program which asks for a name.
i.    It returns the name in lower case
ii.    It returns the name in UPPER case
iii.    It returns the name with the first letter as UPPER case and the rest lower (You will need to use string slicing as above)

GET STARTED HELP!

name=input("

print ("Your name is

print ("Your name in lower case is  )

print ("Your name in upper case is  )

print ("Your name with first letter upper case is and the rest lower is

DONE? Prove you have done it by showing your teacher or loading it to Edmodo

 

 

WHAT I NEED TO KNOW

In the following area you will:

6.3.1 be able to write programs that make appropriate use of primitive data types (integer, real, Boolean, char)

6.3.2 be able to write programs that make appropriate use of variables and constants

The supported functionality is as follows:

Comments        Anything on a line after the character # is considered a comment.
Identifiers          Identifiers are any sequence of letters, digits and underscores, starting with a letter. Both upper and lower case are                                    supported.

Variables            may be explicitly assigned a data type during declaration.
                             Variables may be implicitly assigned a data type during initialisation.
integer                int
real                      float
boolean              bool
character            str
conversion         Conversion is used to transform the data types of the contents of a variable using:

                              > int()
                              > str()

                              > float()

                              > bool()

                              > list().

                             Conversion between any allowable types is permitted.


constants           Constants are conventionally named in all upper-case characters.

6.3.1  write programs that use one and two-dimensional structured data types (string, array, record)

name      data type     description

string        str                 A sequence of characters
array         list                A sequence of items with the same (homogeneous) 
record       list                A sequence of items, usually of mixed (heterogenous) 


List / Record Dimensions- The number of dimensions supported by the PLS is two. The PLS does not support ragged data structures. Therefore, in a list of records each record will have the same number of fields.

List methods
The supported functionality is as follows:


Function                           Description
list.append(item)             Adds an item to the end of the list
del <list>[<index>]          Removes the item at index from list
list.insert (index, item)    Inserts an item just before an existing one at index

 

<item> = list()
<item> = []                       Two methods of creating a list structure. Both are empty

6.3.3 be able to write programs that manipulate strings (length, position, substrings, case conversion)

The supported functionality is as follows:

len() Returns the length of

find() Returns the location of in the original. Returns -1, if not found

index() Returns the location of in the original. Raises an exception if not found

isalpha() Returns True, if all characters are alphabetic (a–z)

isalnum() Returns True, if all characters are alphabetic (a–z) and digits (0–9)

isdigit() Returns True, if all characters are digits (0–9), exponents are digits

isnumeric() Returns True, if all characters are numeric (0–9), exponents and fractions are numeric replace(s1,s2) Returns original string with all occurrences of s1 replaced with s2

split() Returns a list of all substrings in the original, using as the separator

strip() Returns original string with all occurrences of ‘char’ removed from the front and back

upper() Returns the original string in upper case

lower() Returns the original string in lower case

isupper() Returns True, if all characters are upper case

islower() Returns True, if all characters are lower case Concatenation of strings is done using the + operator

Click here to download Python file to complete Data Boocamp 3. Then add to your directory and then open in Python

Click here to download Python file to complete Data Boocamp 4. Then add to your directory and then open in Python

BOOTCAMP 5- STRINGS

STEP 1- Open Python

STEP 2- Open the document to the right

STEP 3- Copy the text into Python

STEP 4- Using the code help below complete all of the tasks

STEP 5- Prove you have done it by showing your teacher or loading to Edmodo

strip() 
upper() 
islower() 
find()
isalpha() 
len() 
index()
lower()
isdigit()
isnumeric()
split() 
isupper() 
isalnum() 

bottom of page