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

Assignment 1C F4AB - Introduction

Uploaded by

nzamathobeka756
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)
33 views

Assignment 1C F4AB - Introduction

Uploaded by

nzamathobeka756
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/ 2

CSC1015F Assignment 1C

Introduction

Assignment Instructions
The questions in this assignment give you practice in typing in and editing programs.

Question 1 [20 marks]


Retype the following program into a file called secret.py and test that it runs. The program must
be identical, down to the last bit of punctuation, including the spaces at the beginning of some lines!

Note: If you copy and paste code, you will most probably have problems submitting it to the
Automarker. Furthermore, leave the author of the code as “Hussein Suleman” as that will be a way
of referencing/acknowledging the author. Remember that if we do not acknowledge the author, that
constitutes plagiarism.

You may need to create directories as per the instructions in the orientation manual.
# Program to guess a secret number
# Hussein Suleman
# 10 February 2011

secret_number = 42 # Create secret number in program


guess = 0 # Variable to store user's guess

# As long as we have not found the secret number


while not guess == secret_number:
# Get a new guess from the user
guess = eval(input('?'))
# Check if guess is too low
if guess < secret_number:
print('lo')
# or too high
elif guess > secret_number:
print('hi')

print('Correct!') # Print message indicating success

This program is a classic from the early days of Computer Science. A user is expected to guess
numbers until he or she converges to a secret internal number. At each incorrect guess, the system
lets the user know if the number is too high or too low.

Page 1 of 2
Sample Input/Output (The input from the user is shown in bold):
? 22
lo
? 55
hi
? 42
Correct!

Question 2 [20 marks]


Edit the program from Question one so that the messages printed are more user-friendly. You need
to copy the secret.py file from the first question to a file called secret_2.py.

Change each of the messages printed to the screen to be the same as the example output below.

User-friendliness of programs was a concept that gained popularity in the 1980s, where programs
were made easier for human beings to identify with. This has since grown into the current field of
Usability Engineering, which you will learn about while studying Computer Science.

Sample Input/Output (The input from the user is shown in bold font):
What is the secret number? 14
That is way too low. Please try again.
What is the secret number? 337
That is much too high. Please try again.
What is the secret number? 48
That is much too high. Please try again.
What is the secret number? 40
That is way too low. Please try again.
What is the secret number? 0
That is way too low. Please try again.
What is the secret number? 42
Congratulations, you have guessed the secret number!

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

Page 2 of 2

You might also like