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

Assignment (1)

The document outlines the CSC1010H Assignment 2, which focuses on Python programming skills involving input/output, string manipulation, and numeric data. It includes four exercises: creating a chatbot program, formatting credit card information, calculating the area of a hexagon, and drawing initials using Python Turtle. Students are required to submit their completed programs in a ZIP file following specific naming conventions.

Uploaded by

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

Assignment (1)

The document outlines the CSC1010H Assignment 2, which focuses on Python programming skills involving input/output, string manipulation, and numeric data. It includes four exercises: creating a chatbot program, formatting credit card information, calculating the area of a hexagon, and drawing initials using Python Turtle. Students are required to submit their completed programs in a ZIP file following specific naming conventions.

Uploaded by

happyweirdo.am
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Version: 12/04/2024 10:10

CSC1010H Assignment 2
Python Input/Output, String and Numbers

Introduction
Learning outcomes
Skills
• Construct python programs composed of sequences of simple statements and involving the
input, output, and manipulation of numeric and alphanumeric data.

Knowledge
• The form of variable identifiers, assignment statements, print statements.
• Python data types, operators and operator precedence:
o String: string slicing and concatenation, multiplication,
o Int and float: addition, subtraction, multiplication, division, integer division,
modulus.
• Expressions involving functions, string and arithmetic manipulation, and casting.
• Form of import statement, and functions in the math and random modules.

Exercise 1 [25 marks]


Eugene Goostman is a “chatbot” program that, posing as a 13-year-old, English speaking, Ukrainian
boy, that some consider passed the Turing test in 2014.According to the BBC, through a series of 5-
minute conversations with Eugene, 33% of a panel of judges were convinced they were conversing
with a human. (Turing predicted that by the year 2000 a machine would be capable of convincing
30% of human judges.)

Write a program called ‘eugenejunior.py‘ that interacts with the user in a conversational
manner by asking questions and responding appropriately. The program should:

1. Ask the user for name, surname, and preferred title, responding with a greeting that
includes their title, first name initial and surname.
2. Ask the user for the course code of their current course and ask what the first three letters
stand for, responding with an expression of interest.
3. Ask the user for their weight in kilograms, responding with the equivalent in US pounds and
ounces.
4. Ask for the current date, expressed as dd/mm/yy, and for the user’s year of birth,
responding with the age they will be in the current year.

Here is an example of how Eugene Junior should behave:


Hello, I am Eugene Junior.
What is your first name?
Stephan
What is your last name?
Jamieson
And what is your preferred title?
Mr
Hi Mr S. Jamieson!
What is the course code of your current course?

Continued
2

MAM1000
So, what does 'MAM' stand for?
Mathematics
Mathematics sounds interesting.
What weight are you in kilograms?
87.5
That's 192 lbs and 14 ounces in the US!
What's today's date (dd/mm/yy)?
12/04/24
And what year were you born?
1967
Okay, so you're 55 this year.
Nice talking to you, bye!

(User input is shown in a bold font.)

You may assume today’s date is always at least in the year 2000. There are 28.35 grammes in an
ounce.

RECOMMENDATION: Develop your program in stages. Start with a version that respond to a names
and title, then the course code queries, and so on.

Exercise 2 [25 marks]


Create a program called ‘creditcard.py’. It should allow the user to enter information about a
credit card account, and then produce a formatted output of that information. Here is an example of
expected behaviour:
Enter the card holder's name:
Eugene Goostman
Enter the 16 digit card number (no spaces please):
1234456778901234
Enter the date of issue (mm:yy):
03:23
Enter the expiry date (mm:yy):
05:25
Enter the 3 digit security code:
231
Enter the credit limit (Rand):
20000
Enter the balance (Rand):
1478

+------------- Credit Card Account --------------+


| Card holder: Eugene Goostman |
| Card number: 1234 4567 7890 1234 |
| Date of issue: 03/23 Expiry date: 05/25 |
| Security code: 231 |
| Credit limit: 20000.00 Rand |
| Available: 18522.00 Rand |
| Balance: 1478.00 Rand |
+------------------------------------------------+

Continued
3

(User input is shown in a bold font.)

Exercise 3 [25 marks]


Write a program called ‘hexagonarea.py‘ that, given the length of side of a regular hexagon,
calculates and prints the area, rounded and formatted to 3 decimal places.

3√3
𝐴𝐴𝐴𝐴𝐴𝐴𝐴𝐴 = 𝑠𝑠𝑠𝑠𝑠𝑠𝑠𝑠 2
2
Here is an example of program behaviour:
Enter the length of the side (cm):
12
The area of a hexagon of side 12 is 374.123.

(User input is shown in a bold font.)

Exercise 4 [25 marks]


Write a program using Python Turtle in a file called ‘initials.py‘ which draws your own initials,
i.e. the first character of your name and the first character of your surname, using block letters. If
they are the same character, use the first two characters of your name. Use a different colour for
each character, other than black. Also, horizontally centre the letters and ensure that they are 200
steps high. Here is an example of what it should look like:

Continued
4

Marking and Submission


Submit the eugenejunior.py, creditcard.py, hexagonarea.py, and initials.py
files contained within a single .ZIP file to the automatic marker. The zipped file should have the
following naming convention:
yourstudentnumber.zip

Marking Guide
Question 1 Eugene Junior 25
Question 2 Credit card 25
Question 3 Hexagon area 25
Question 4 Initials 25
Total 100

Note that question 4, initials.py, will be marked manually.

End

You might also like