question archive Foundation Computing 2 (6G3Z3107_2023_1) Assignment title: Python Programming and Design Introduction This coursework will consolidate your learning of Foundation Computing 2: Programming unit in Semester 2
Subject:Computer SciencePrice: Bought3
Foundation Computing 2 (6G3Z3107_2023_1)
Assignment title: Python Programming and Design
Introduction
This coursework will consolidate your learning of Foundation Computing 2: Programming unit in
Semester 2.
Please complete ALL tasks and submit a zipped file, which contains TWO files, coursework.py and design.
pdf (for Task C.3 and F.2, see below) through Moodle for marking. The zip file should be named as
yourSurname_initials_ID.zip, for example, Zhang_Y_55011015.zip.
Task A: Python I/O [10]
1. Print a heading “Section A”.
2. Use ‘input’ function to ask user to input their name, and print a welcome message, “Welcome,
<user’s name>”. [10]
Task B: Python expressions [10]
1. Print a heading “Section B”.
2. Write code to convert the temperature 100F (100 degrees in Fahrenheit) to degrees in Celsius, and
print “The temperature in Celsius is:”, followed by your converted result, on the same line.
The formula is the reverse of the formula you saw in the labs for converting Celsius to
Fahrenheit, i.e. Subtract 32, then multiply the result of the subtraction by 5, then divide the
result of the multiplication by 9. [10]
Task C: Loops [15]
1. Print a heading “Section C”.
2. Write code to calculate successive powers of 3 up to a maximum of 10 (loops from 0 to 10). You
may use the function pow(), or use ** operator. Print the heading “Loops calculation.” Print the
results with text as shown below:
Example:
Loops Calculation.
3 to the power 0 is 1
3 to the power 1 is 3
3 to the power 2 is 9
3 to the power 3 is 27
… …
3 to the power 10 is 59049 [5]
3. Design (structured English) an algorithm to calculate the following,
[5]
4. |
Write Python code to implement the design above. Print the result with text as shown below: |
The sum of squares from 1 to 100 is 338350 [5]
4
Task D: Python list [15]
1. Print a heading “Section D”.
2. For a list fruits = [‘apple’, ‘banana’, ‘pear’, ‘cherry’, ‘melon’], write code to print the second item in
the list. [5]
3. Write code to add a new item ‘water melon’, then print the updated list. [5]
4. Write code to delete the item ‘pear’, then print the updated list. [5]
Task E: Python file [15]
1. Print a heading “Section E”.
2. Use the enclosed file, country.csv, write code to search the file and print the names of the
counties, whose life expectancy is more than 75. [5]
3. Write code to search the file, and print the names of countries, whose GNP is more than 1000.
[5]
4. Write code to search the file, and print the names of countries, whose life expectancy more than
75 AND GNP more than 1000. You will need to add the necessary declarations to open and close
the file etc. [5]
Task F: Python Encryption [10]
1. Print a heading “Section F”.
2. Design (structured English) an algorithm to count the number of occurrences of all of the
different symbols in a character string, “GOOGLE”. [5]
3. Write Python code to implement the design above. Print the results on the screen. For example,
for the string “GOOGLE” it should be something like:
GOOGLE:
G has 2 occurrences
O has 2 occurrences
L has 1 occurrences
E has 1 occurrences
(if you want to make it grammatically correct when there’s only 1 occurrence you will need a bit
more code.) [5]
Task G: Python graphics [10]
1. Print a heading “Section G”
2. Write code to draw a regular pentagon, using the side_length = 100 pixels. You need to
import Turtle Graphics module, and create your own turtle. [5]
3. Write code to draw a regular five-pointed star, using the side_length = 100 pixels, BLUE pen to
draw and fill in YELLOW colour, You can arrange two shapes freely as long as they do not overlap,
as shown below: [5]
Example:
5
Task H: OO Programming and functions [15]
1. Print a heading “Section H”
2. Using the code bellow, write a Python program to
a |
create an object, an instance of the Vehicle Class, then print all attributes values (name, |
colour and mileage of the instance). |
[5] |
b |
add a function change_colour() in the Vehicle class to change the colour attribute value, |
[5] |
|
c |
add a function show_description() in the Vehicle class to print the current values of all |
the instance attributes, then call this function in the object you just created. |
[5] |
class Vehicle:
def __init__(self, name, colour, mileage):
self.name = name
self.colour = colour
self.mileage = mileage