首页 > > 详细

CSC108留学生辅导、讲解a1_warmup、Python程序调试、辅导Python语言 辅导Web开发|辅导Python程序

CSC108 Assignment 1
Warmup: Cleaning Up Code
Your friend, Bob, has written a random program, playing around with the basics of
Python. But for such simple operations, he feels as though his file is way too long. He
remembers hearing from someone that, when you're trying to program something
really simple, you'll ofen find that "long code is wrong code". Even if the code is
working properly, making it shorter would make it much better and cleaner to handle.
Bob's file is named a1_warmup.py. All Bob wants is to make the file shorter. He
doesn't want the way the code works to change. Could you clean up this code for him,
using functions and getting rid of other useless things? (For example, by putting all
the mathematical calculations into one equation instead of splitting each step up, or,
when checking if a boolean value is True, instead of writing the redundant code 'if
(bool == True)', simply writing 'if (bool)', etc.).
Try to get the file down to less than 40 lines.
This part of the assignment is just a warm-up exercise and will not be graded for
correctness, but for participation/effort, so don't worry too much about details/accuracy,
and spend a little bit of time practicing the art of cleaning up bad code.
Part A: Compatibility Calculator
Bob's back again, and this time, he's in love. He noticed a new girl in his Math Proofs
class and even though they haven't really talked yet, he's convinced they are meant
for each other. Just to be sure though, Bob wanted to double-check their
compatibility. He remembered a quite accurate, fool-proof compatibility calculation
kids used to do back in the day – something involving a complex algorithm that
counted the number of times the letters in the word "LOVES" appears in two names,
and then added digits together to calculate a percentage . 1
Much to his surprise, that completely inaccurate, childish compatibility calculator
stated that 'Bob Y' and 'Bobbette Z' have a compatibility of only 44%!
This is an actual thing kids used to do. If you're curious about this method (and maybe want to try it out on your own 1
Bobbette ;)), I can tell you about it if you ask, but it's not really relevant to the assignment, so I didn't want to go into it in detail
on this assignment page.CSC108 Assignment 1
This was unacceptable, Bob decided. The issue, he decided, was that considering only
names to measure compatibility lef out one of the most important factors that truly
determines how well-matched two people are. Their zodiac signs.
So he decided to make his own, better version.
And he needs your help to finish it.
Finish the code in a1_part1.py (included in a1_files.zip), as directed by the docstrings
and examples in the file.
If your calculator is working properly, it should give the following output for the given
input (try these out to test your code; you would have to run your program again to
test out each set of people):
(1)
Give me your first and last name: Bob Y
Give me your birthdate in the format YYYY-MM-DD: 1998-08-30
=====
Give me your crush's first and last name: Bobbette Z
Give me your crush's birthdate in the format YYYY-MM-DD: 1998-09-01
You are 85.0% compatible in love!
(2)
Give me your first and last name: Sadia Sharmin
Give me your birthdate in the format YYYY-MM-DD: 1957-08-24
=====
Give me your crush's first and last name: Ryan Gosling
Give me your crush's birthdate in the format YYYY-MM-DD: 1980-11-12
You are 110.0% compatible in love!
(3)
Give me your first and last name: Homer Simpson
Give me your birthdate in the format YYYY-MM-DD: 1955-05-12
=====
Give me your crush's first and last name: Marge Simpson
Give me your crush's birthdate in the format YYYY-MM-DD: 1955-03-19
You are 140.0% compatible in love!CSC108 Assignment 1
Part B: Bringing in Lists
A lot of you may have made the observation that some of the things I had you do in
the previous part would be much easier if I had just given you some of the data in the
form of lists, rather than these long, convoluted strings! Why didn't I do that? Well,
because I want you to do it yourself. :D
For this part of the assignment, I want you to look through the code that you have
been given in a1_part2.py which is the exact same starter code as a1_part1.py, but
this time, you will modify the starter code and then complete all the functions to use
your modifications. More specifically, you should do the following:
1. Go through the starter code and decide: Which parts of this would be better
represented using a list? What can I make cleaner by bringing in lists?
2. Edit the starter code at each of these parts to use lists.
3. Complete all the functions so they work with your modified code. For the functions
that are not affected by your changes, you may simply copy/paste whatever code
you had as your answer for them in part 1 - that's perfectly fine, and expected.
Note that you should NOT change the function names, parameters, or docstring
descriptions for this part. Only certain function bodies and the constant values at the
top of the code should be affected. Again, do not modify any function names or
parameters. Your functions should be returning the same output as they did in part 1.
Part C: Improving "Accuracy"
Optional for bonus marks up to 5% extra on the assignment
Make a new file called a1_part3.py, and copy/paste your code from part 2 or part 1
into this new file. Then, make modifications to this file as follows:
You may have noticed that the compatibility calculator asks the user for birth years,
but actually does nothing with them. For this part of the assignment, I want you to
think up some sort of extra rule, any rule at all, that involves either (a) the years, and/
or (b) some other piece of information that you could ask the user – e.g. favourite CSC108 Assignment 1
colour or something, and adds another extra layer to how the compatibility is
calculated. e.g. A very simple rule could be to check if the two people are born on the
same year, you double their compatibility. This is a pretty boring and easy to
implement rule however, and for this part you will be marked mainly on creativity and
effort, so please try to think of something a little more interesting. :) Have fun with it!
Your program in a1_part3.py should calculate a new compatibility score based on
whatever new rule you have decided to add in. You may add in new functions and
variables, as needed.
Important: Enhancements.txt File
If you do this part, you must hand in an enhancements.txt file which has the
following:
1) List what enhancement(s) you added
2) Briefly describe how the enhancement works and if you want, the process you
went through to create this enhancement
The enhancements.txt file is very important. You must hand in a description of your
enhancements to receive a bonus for part C. Even if your part 3 is incomplete or didn't
work how you wanted it to, please include a description of your attempts in the
enhancements text file along with your attempted code for partial marks. :)
Guidelines/Cleanup:
Before handing in your code, make sure to do the following:
1. Check that you have followed our style guide: https://mcs.utm.utoronto.ca/
~108s19/python_style_guide.shtml
2. Remove any code you added just for testing, such as print function calls.
3. Remove any pass statement where you have added the necessary code.
4. For part 3: If you added any new functions, check your docstrings to make sure
they are precise and complete and that they follow the conventions of the
Function Design Recipe.
5. Make sure your code runs! If you have some attempts that you want to get partial
marks for, great. Please submit your attempts; however, if your incomplete/
incorrect attempts cause your code to crash then please comment out invalid CSC108 Assignment 1
code before handing it in. We must be able to run your program in order for the
autograder to give you marks for other functions that might work.
Note: You should never change the name of any function given in the starter code, as
doing so will make our auto-grader fail. You may only change things like this for part 3
where you are mainly graded for your creativity and effort.
What you will be handing in:
Submit all the following files on MarkUs by February 17th, 2019, midnight:
1. a1_warmup.py
2. a1_part1.py
3. a1_part2.py
4. Optional: a1_part3.py and enhancements.txt
Again, please make sure your code is cleaned up and that your main program runs! If
your program crashes as soon as we run it, our autograder will give you a 0 on all your
functions, even ones that might work!
Assessment:
Your mark will be based on both correctness as well as cleanliness of code (following
the Python style guidelines, following design recipe, avoiding repetitive code, etc.).
For part 3, you will be graded on cleanliness/efficiency of code, creativity and effort.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!