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

IO, Control (If)

This document provides instructions for Assignment 2B involving Python programs that use input/output statements, if/if-else control flow statements, and numerical manipulation. It includes 4 questions to write Python programs that: 1) Output an ASCII art computer science logo using print statements. 2) Validate the validity of a time input from a user by checking if hours, minutes, and seconds are within expected ranges. 3) Generate a personalized spam message based on user input for name, country, and money amount. 4) Determine if a year is a leap year based on whether it is divisible by 400, divisible by 4 but not 100. Students are instructed to submit a zip file containing the 4 Python

Uploaded by

Lesego Wubet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

IO, Control (If)

This document provides instructions for Assignment 2B involving Python programs that use input/output statements, if/if-else control flow statements, and numerical manipulation. It includes 4 questions to write Python programs that: 1) Output an ASCII art computer science logo using print statements. 2) Validate the validity of a time input from a user by checking if hours, minutes, and seconds are within expected ranges. 3) Generate a personalized spam message based on user input for name, country, and money amount. 4) Determine if a year is a leap year based on whether it is divisible by 400, divisible by 4 but not 100. Students are instructed to submit a zip file containing the 4 Python

Uploaded by

Lesego Wubet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CSC1015F Assignment 2B (70 Marks)

Console Input/Output and Control (if)

Assignment Instructions
This assignment involves constructing Python programs that use input and output statements, 'if'
and 'if-else' control flow statements, and statements that perform numerical manipulation.
You may need to use additional attributes of the print statement that control what is printed at the
end of each print statement (end="\n") and separating each value in a list of values (sep=" ").
For example:

print ("a","b","c")

displays "a b c"

print ("a","b","c", sep="|")

displays "a|b|c"

NOTE Your solutions to this assignment will be evaluated for correctness. Assignments that follow
(starting with Assignment 4) will also be evaluated for the following qualities:

• Documentation
o Use of comments at the top of your code to identify program purpose, author and
date.
o Use of comments within your code to explain each non-obvious functional unit of
code.
• General style/readability
o The use of meaningful names for variables and functions.
• Algorithmic qualities
o Efficiency, simplicity

These criteria will be manually assessed by a tutor and commented upon. In future assignments, up
to 10 marks will be deducted for deficiencies.

Question 1 [15 marks]


ASCII Art is a technique to create fancy effects using simple text output.

By using only print statements, write a program called 'com_sci.py' that outputs the following:

Page 1 of 4
Do not include the blue guides - these are there simply so you can see how many spaces are
between characters.

Here’s the raw text for further reference:

- - - - - - - - - - - - - - - - - - - - - - - - -
/ - - - / - - - | - - / - - - | | - - - | | | | \ | | |
| | \ - - - \ | | \ - - - \ | | - | | | | \ | | |
| | - - - - - - ) | | - - - ) | - | | | - | | | \ | - |
\ - - - - | - - - - / - - - | - - - / | | \ - - - / | - | \ - ( - )

Some of the backslashes (\) may need to be escaped (written as \\ instead). Search online to find out
why this is necessary.

Question 2 [20 marks]


Write a program called 'time.py' for checking the validity of a time entered by the user as a set of
three integers. In professional software, it is never assumed that input from users is valid so you too
need to do this in your programs.

In this case, you want to check if the number of hours is between 0 and 23 (inclusive), the number of
minutes is between 0 and 59 (inclusive) and the number of seconds is between 0 and 59 (inclusive).

Sample I/O (The input from the user is shown in bold font):
Enter the hours:
21
Enter the minutes:
7
Enter the seconds:
7
Your time is valid.

Sample I/O (The input from the user is shown in bold font):
Enter the hours:
25
Enter the minutes:
-7
Enter the seconds:
0
Your time is invalid.

Sample I/O (The input from the user is shown in bold font):
Enter the hours:
21
Enter the minutes:
7
Enter the seconds:
72
Your time is invalid.
Question 3 [15 marks]
Write a program called ‘spam.py’ to generate a personalised spam message based on the user's full
name, country and a sum of money. Use the following template for the spam message, with a blank line
before the message starts.

Dearest <first_name>
It is with a heavy heart that I inform you of the death of my father,
General Fayk <last_name>, your long lost relative from Mapsfostol.
My father left the sum of <money>USD for us, your distant cousins.
Unfortunately, we cannot access the money as it is in a bank in <country>.
I desperately need your assistance to access this money.
I will even pay you generously, 30% of the amount - <money30>USD,
for your help. Please get in touch with me at this email address asap.
Yours sincerely
Frank <last_name>

Sample IO (The input from the user is shown in bold font):


Enter first name:
Patrick
Enter last name:
Star
Enter sum of money in USD:
1234
Enter country name:
South Africa

Dearest Patrick
It is with a heavy heart that I inform you of the death of my father,
General Fayk Star, your long lost relative from Mapsfostol.
My father left the sum of 1234USD for us, your distant cousins.
Unfortunately, we cannot access the money as it is in a bank in South Africa.
I desperately need your assistance to access this money.
I will even pay you generously, 30% of the amount - 370.2USD,
for your help. Please get in touch with me at this email address asap.
Yours sincerely
Frank Star

Hint: Use "\n" at the end of your input string to move to the next line before input.
Question 4 [20 marks]
Write a program called leapYear.py to determine whether a year is a leap year or not. A year is a
leap year if (a) it is divisible by 400 or (b) it is divisible by 4 but not by 100. Your program must accept
input from the user in the form of an integer representing the year. Then, it checks if it is a leap year
or not.

Sample I/O (The input from the user is shown in bold font):

Enter a year:
2023
2023 is not a leap year.
Sample I/O (The input from the user is shown in bold font):
Enter a year:
2020
2020 is a leap year.

Submission
Create and submit to the automatic marker a Zip file called ABCXYZ123.zip (where ABCXYZ123 is
YOUR student number) containing com_sci.py, spam.py, time.py and leapYear.py.

NOTES:

1. FOLDERS ARE NOT ALLOWED IN THE ZIP FILE.


2. As you will submit your assignment to the Automarker, the Assignment tab will still say “Not
Complete” or “In Progress” or something similar. THIS IS COMPLETELY NORMAL. IGNORE IT.

You might also like