Computer Science Tasks
Computer Science Tasks
Instructions
This is the module project and is worth 50% of the module mark.
This project covers the the four topics covered during the module:
Syntax
Strings
Conditionals and Control Flow
Functions
The project gives each student an opportunity to put into practice what they
have learned about programming in Python by problem-solving and completing a
varied set of tasks.
Write code for each task using the Programiz online Python compiler available
at:
https://www.programiz.com/python-programming/online-compiler/
When you are happy with your code, paste it into the space provided at the very
end of this Word document. Then, attach the completed Word document to the
PROJECT assignment n Assignments and click on HAND-IN.
You can use the class notes (videos and PowerPoints), the Codecademy lessons,
and the internet to help you complete the tasks.
GOOD LUCK!!
Task 1 (20 marks)
Write code which prints the first, second and sixth elements of this string.
Hint: Google slicing in Python.
[3 marks]
Do an internet search for the next line of lyrics in the song whose first line of
lyrics is the statement outputted by running the line of code above.
Create a new string called new_string3 which contains the first two lines of
lyrics in this song.
Use the len function and print command to print the length of new_string3.
[2 marks]
Store this new lowercase/uppercase version of the song lyrics in a new variable
called new_string4.
Hint: Do an internet search for upper() and lower() methods for strings in
Python.
[1 mark]
Write code to create a function called my_fn_1 which takes as a first argument
a string, and takes as a second argument a numerical value.
If the length of the inputted string exceeds this numerical value, the function
should return a statement which reads:
“The input is too long as it exceeds the maximum permitted value of x.”
If the length of the inputted string is less than or equal to the numerical value
(second argument), the function should return a statement which reads:
“The input length is within permitted limits. There are y characters remaining.”
Having defined my_fn_1, run the code below to check that your code works
correctly:
Task 3 (5 marks)
The grading system to be used is: Distinction (70-100), Upper Merit (60-69),
Merit (50-59), Pass (40-49), Not Achieved (0-39).
This function should return the correct grade for any whole number percentage
mark entered.
Having defined my_fn_2, run the code below to check that your code works
correctly:
print(my_fn_2(92))
print(my_fn_2(66))
print(my_fn_2(50))
print(my_fn_2(43))
print(my_fn_2(10))
[5 marks]
Copy and paste your code into the spaces provided below.
Spelling errors, typos, formatting errors, etc. will cause your code not to run
correctly.
Task 1
new_string2 = "education"
print (new_string + new_string2)
Task 2
def my_fn_1(a_string,x):
y = abs((int(x) - len(a_string)))
if len(a_string) > x:
return ("The input is too long as it exceeds the maximum permitted value
of " + str(x))
else:
return ("The input length is within permitted limits. There are ") + str(y) +
(" characters remaining.")
print(my_fn_1("I think this string is too long", 10))
print(my_fn_1("I think this string is fine", 30))
Task 3
def my_fn_2(n):
if n > 69:
return ("Distinction")
elif n > 59:
return ("Upper Merit")
elif n > 49:
return ("Merit")
elif n > 39:
return ("Pass")
else:
return ("Not Achieved")
print(my_fn_2(92))
print(my_fn_2(66))
print(my_fn_2(50))
print(my_fn_2(43))
print(my_fn_2(10))