讲解:CSC108、a1_warmup、Python、PythonWeb|Python

CSC108 Assignment 1Warmup: Cleaning Up CodeYour friend, Bob, has written a random program, playing around with the basics ofPython. But for such simple operations, he feels as though his file is way too long. Heremembers hearing from someone that, when youre trying to program somethingreally simple, youll ofen find that long code is wrong code. Even if the code isworking properly, making it shorter would make it much better and cleaner to handle.Bobs file is named a1_warmup.py. All Bob wants is to make the file shorter. Hedoesnt 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 allthe 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 forcorrectness, but for participation/effort, so dont worry too much about details/accuracy,and spend a little bit of time practicing the art of cleaning up bad code.Part A: Compatibility CalculatorBobs back again, and this time, hes in love. He noticed a new girl in his Math Proofsclass and even though they havent really talked yet, hes convinced they are meantfor each other. Just to be sure though, Bob wanted to double-check theircompatibility. He remembered a quite accurate, fool-proof compatibility calculationkids used to do back in the day – something involving a complex algorithm thatcounted the number of times the letters in the word LOVES appears in two names,and then added digits together to calculate a percentage . 1Much to his surprise, that completely inaccurate, childish compatibility calculatorstated that Bob Y and Bobbette Z have a compatibility of only 44%! This is an actual thing kids used to do. If youre curious about this method (and maybe want to try it out on your own 1Bobbette ;)), I can tell you about it if you ask, but its not really relevant to the assignment, so I didnt want to go into it in detailon this assignment page.CSC108 Assignment 1This was unacceptable, Bob decided. The issue, he decided, was that considering onlynames to measure compatibility lef out one of the most important factors that trulydetermines 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 docstringsand examples in the file.If your calculator is working properly, it should give the following output for the giveninput (try these out to test your code; you would have to run your program again totest out each set of people):(1)Give me your first and last name: Bob YGive me your birthdate in the format YYYY-MM-DD: 1998-08-30=====Give me your crushs first and last name: Bobbette ZGive me your crushs birthdate in the format YYYY-MM-DD: 1998-09-01You are 85.0% compatible in love!(2)Give me your first and last name: Sadia SharminGive me your birthdate in the format YYYY-MM-DD: 1957-08-24=====Give me your crushs first and last name: Ryan GoslingGive me your crushs birthdate in the format YYYY-MM-DD: 1980-11-12You are 110.0% compatible in love!(3)Give me your first and last name: Homer SimpsonGive me your birthdate in the format YYYY-MM-DD: 1955-05-12=====Give me your crushs first and last name: Marge SimpsonGive me your crushs birthdate in the format YYYY-MM-DD: 1955-03-19You are 140.0% compatible in love!CSC108 Assignment 1Part B: Bringing in ListsA lot of you may have made the observation that some of the things I had you do inthe previous part would be much easier if I had just given you some of the data in theform of lists, rather than these long, convoluted strings! Why didnt I do that? Well,because I want you to do it yourself. :DFor this part of the assignment, I want you to look through the code that you havebeen given in a1_part2.py which is the exact same starter code as a1_part1.py, butthis time, you will modify the starter code and then complete all the functions to useyour modifications. More specifically, you should do the following:1. Go through the sCSC108留学生作业代写、代做a1_warmup作业、Python程序作业调试、代写Python语言作业 代写Web开tarter code and decide: Which parts of this would be betterrepresented 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 functionsthat are not affected by your changes, you may simply copy/paste whatever codeyou had as your answer for them in part 1 - thats perfectly fine, and expected.Note that you should NOT change the function names, parameters, or docstringdescriptions for this part. Only certain function bodies and the constant values at thetop of the code should be affected. Again, do not modify any function names orparameters. Your functions should be returning the same output as they did in part 1.Part C: Improving AccuracyOptional for bonus marks up to 5% extra on the assignmentMake a new file called a1_part3.py, and copy/paste your code from part 2 or part 1into 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 tothink 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 1colour or something, and adds another extra layer to how the compatibility iscalculated. e.g. A very simple rule could be to check if the two people are born on thesame year, you double their compatibility. This is a pretty boring and easy toimplement rule however, and for this part you will be marked mainly on creativity andeffort, 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 onwhatever new rule you have decided to add in. You may add in new functions andvariables, as needed.Important: Enhancements.txt FileIf you do this part, you must hand in an enhancements.txt file which has thefollowing:1) List what enhancement(s) you added2) Briefly describe how the enhancement works and if you want, the process youwent through to create this enhancementThe enhancements.txt file is very important. You must hand in a description of yourenhancements to receive a bonus for part C. Even if your part 3 is incomplete or didntwork how you wanted it to, please include a description of your attempts in theenhancements 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.shtml2. 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 surethey are precise and complete and that they follow the conventions of theFunction Design Recipe.5. Make sure your code runs! If you have some attempts that you want to get partialmarks for, great. Please submit your attempts; however, if your incomplete/incorrect attempts cause your code to crash then please comment out invalid CSC108 Assignment 1code before handing it in. We must be able to run your program in order for theautograder 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, asdoing so will make our auto-grader fail. You may only change things like this for part 3where 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.py2. a1_part1.py3. a1_part2.py4. Optional: a1_part3.py and enhancements.txtAgain, please make sure your code is cleaned up and that your main program runs! Ifyour program crashes as soon as we run it, our autograder will give you a 0 on all yourfunctions, even ones that might work!Assessment:Your mark will be based on both correctness as well as cleanliness of code (followingthe 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.转自:http://ass.3daixie.com/2019021854008481.html

你可能感兴趣的:(讲解:CSC108、a1_warmup、Python、PythonWeb|Python)