代写Assignment 2代做留学生Python程序

Assignment 2: due 11:59 pm on Saturday, October 5, 2024

Summary of Instructions

Note

Read the instructions carefully and follow them exactly

Assignment Weight

As outlined in the syllabus, this assignment is worth 2.5% of your final grade

Due Date

This assignment is due  11:59 on Saturday, October 5, 2024

Important

As outlined in the syllabus, late submissions will not be accepted

Any files with syntax errors automatically be excluded from grading.  Be sure to

test your code before you submit it

For all functions, make sure you've written good docstrings that include type

contract, function description and the preconditions if any.  That includes functions

you write both in Part 1 and Part 2.

This is an individual assignment. Please review the Plagiarism and Academic Integrity policy presented in the first class, i.e.  read in detail pages  16-20 of course outline  (i.e.  slides of Lecture  1).  You can find that file on Brightspace under Lecture 1. While at it, also review Course Policy on missing assignments on page 14.

The goal of this assignment is to learn and practice the concepts covered thus far:  function  design,  function calls, branching  (i.e.   if statements),  strings.   You  can  make  multiple  submissions,  but  only  the  last  submission  before  the deadline will be graded. What needs to be submitted is explained next.

Your  grade will  partially  be  determined  by  automatic  (unit) tests that will test your  functions.   All  the  specified requirements below are mandatory (including function names).  Any requirement that is specified and not met may/will result in deduction of points.

Submit your assignment by the deadline via Brightspace (as instructed and practiced in the first lab.) You can make multiple submissions,  but only the last submission before the deadline will be graded.   For this  assignment you must submit 5 files as described below.  For each missing file there will be a grade deduction:

The assignment has two parts.  Each part explains what needs to be submitted.  Put all those required documents into a folder called a2_xxxxxx where you changed xxxxxx to your student number, zip that folder (do not use rar compression format) and submit it as explained in Lab 1. In particular, the folder must have the following 5 files:

 for Part 1:  a2_part1_xxxxxx.py, a2_part1_xxxxxx.txt

 for Part 2:  a2_part2_xxxxxx.py a2_part2_xxxxxx.txt and

– references-YOUR-FULL-NAME .txt

I suggest you do part 2 first and then do part 1.

Both of your programs/parts must run without syntax errors.  In particular, when grading your assignment, TAs will first open your file a2_part1_xxxxxx.py with IDLE and press Run Module.  If pressing Run Module causes any syntax error, the grade for Part 1 becomes zero. The same applies to Part 2, when they open and run file a2_part2_xxxxxx.py.

Furthermore, for each of the functions (in Part 1 and Part 2), I have provided one or more tests to test your functions with.   For  example,  you  should  test  function  high_school_quiz from  Part  1  by  making  a  call  in  Python  shell  with high_school_quiz(3,2,15) To obtain a partial mark your function may not necessarily give the correct answer on these tests.  But if your function gives any kind of python error when run on the tests provided below, that question will be marked with zero points.

Section 3, contains tests for Part 1. Tests for Part 2 are provided after each question in Part 2.  To determine your grade, your functions will be tested both with examples provided in Part 2 and Section 3 and with some other examples. Thus you too should test your functions with more example than what I provided in Part 2 and Section 3.

Each function has to be documented with docstrings.

Global variables are not allowed.  If you do not know what that means, for now, interpret this to mean that inside of your functions you can only use variables that are created in that function.  For example, this is not allowed, since variable x is not a parameter of function a_times(a) nor is it a variable created in function a_times(a).  It is a global variable created outside of all functions.

def  a_times(a):

result=x*a

return  result

x=float(input("Give me  a  number:  "))

print(a_times(10))

About references-YOUR-FULL-NAME . txt le:

The file must be a plain text file.  The file must contain references to any code you used that you did not write yourself, including any code you got from a friend, internet, AI engines like chatGPT, social media/forums (including Stack Overflow and discord) or any other source or a person.   The only exclusion from that rule is the code that we did in class, the code done as part the lab work, or the code in your textbook.  So here is what needs to be written in that file.  For every question where you used code from somebody else:

  Write the question number

•  Copy-paste all parts of the code that were written by somebody else.  That includes the code you found/were-given and that you then slightly modified.

•  Source of the copied code:  name of the person or the place on the internet/book where you found it.

While you may not get points for copied parts of the question, you will not be in the position of being accused of plagiarism. Any student caught in plagiarism will receive zero for the whole assignment and will be reported to the dean.

Showing/giving any part of your assignment code to a friend also constitutes plagiarism and the same penalties will apply.  If you have nothing to declare/reference, then just write a sentence stating that and put your first and last name under that sentence in your references-YOUR-FULL-NAME.txt file.

Not including references-YOUR-FULL-NAME.txt file, will be taken as you declaring that all the code in the assignment was written by you.  Recall though that not submitting that file, comes with a grade penalty.

1    Part 1: Math quiz-generator / equation-solver - 40 points

You would like to help in your community center teach elementary and high school students math.  To reach as many kids as possible, you decided to write some software that can automate some tasks for you.  As starting point, you decided to make an automatic quiz generator and grader for elementary school pupils and a quadratic equation solver for highschool pupils – but unlike the solver you did in your Lab 2, this quadratic equation solver needs to handle all possible cases including those when the given quadratic equation has complex numbers for solutions.  In case of elementary school pupils, your understanding is that they already know well addition and multiplication but that they struggle with exponentiation and its inverse.

For this part, I provided you with starter code in file called a2_part1_xxxxxx.py.  Begin by replacing xxxxxx in file name with your student number.  Then open the file.  Your solution (code) for this part must go into that file in clearly indicated spaces.  You are not allowed to delete or comment-out any parts of the provided code except for the keywords pass.

For this part you need to submit two files:  a2_part1_xxxxxx.py and a2_part1_xxxxxx.txt

a2_part1_xxxxxx.py needs to contain your program for Part 1 as explained above and a2_part1_xxxxxx.txt needs to  contain  the  proof that  you  tested  your  two  core  functions  from  this  part,  namely  elementary_school_quiz  and high_school_quiz

1.1    The Core Functions

Your solution in a2_part1_xxxxxx.py must have two functions called: elementary_school_quiz and high_school_quiz.

You should design and test these functions first before moving onto the main part of the program. Here are specifications for the two functions:

elementary_school_quiz:  This function has two parameters, namely an integer flag that takes only values 0 or 1 and an integer n that takes only values  1 or 2.   If  flag is 0,  elementary_school_quiz helps practice the inverse of exponentiation i.e.  logarithm.  But if  flag is 1, elementary_school_quiz helps practice exponentiation.  In both cases  only  questins  with  base  2  will  be  asked.   The  function,  elementary_school_quiz then  generates n math problems that a pupil must answer in turn.  For each question, it generates one random number between 0 and 10 inclusively (check out python’s random module to see if there’s a useful function in there) and asks the pupil for the answer to the math problem with the random number.  Specifically, if flag is 0 and random number generated is, for example, 5 the question asked should be: “2 to what is 32 i.e.  what is the result of log2  (32)?”.  (The reason 32 is picked is because 25  = 32.  See section 3 for more examples.  If  flag is  1 and random number generated is, for example, 6 the question asked should be: “What is the result of 26 ?”

elementary_school_quiz then prompts the pupil for the answer, and checks if her answer is correct.  At the end of n questions, elementary_school_quiz returns the number of questions answered correctly.

high_school_quiz:  This function has three parameters representing three real numbers for the coefficients ofthe quadratic equation ax2 + bx +c = 0.  The function displays/prints the equation frist and then prints its solutions.  The function must display correct and meaningful solutions given any three real numbers for coefficients a, b and c.  See examples in Section 3 to understand what that means.  Please consider the examples to be a part of the function/program specifications that must be followed.

Do not use Python’s complex numbers class to solve this problem.

1.2    The User Interaction i.e.  the main part of the program

Now that you have the two functions that perform the core functionality, you want to make it more user friendly for the pupils (after all, alas, the pupil may not know how to write code and call functions in Python shell). In the main part of your program, write your code in specified places.  You code must follow the behaviour indicated in the example runs in Section 3.

For  example,  for  elementary  school  pupils,  called  Mia,  you  will  first  ask  her  whether  she  would  like  to  practice exponentiation or its inverse.  Then ask her how many practice questions she’d like (if she says 0, then your code should not  ask  her to  solve  any  math  questions).   Using  her responses,  call the  elementary_school_quiz function with the appropriate values. When it returns the number of correct answers, display a message to the pupil:

•  If she go all questions correctly display on screen: Congratulations  Mia!   You’ll  probably  get  an  A  tomorrow . Good  bye  Mia!

•  If she got half of them correctly display on screen:  You  did  ok  Mia,  but  I  know  you  can  do  better .    Good bye  Mia!

•  If she did all incorrectly, display on screen:  I  think  you  need  some  more  practice  Mia .    Good  bye  Mia!

For high school pupils, in the main part of your program in the specified places, you need to write some code that asks the pupil for the coefficients a, b and c.  Then you need to make the call to high_school_quiz to display the solutions. After that your program should ask the pupil if they would like another quadratic equation solved.   If the pupil says anything but yes the program terminates by printing a good bye message as in the examples.  Otherwise, as long as pupil answers yes (and any form of typing yes should be acceptable, including with lots of white space before and after, and with capital letters and lower case letter etc), she should be asked for the coefficients again and the resulting new quadratic equation should be solved.  Since you have not seen while loops yet, I provided the code for that in a2_part1_xxxxxx.py.

The rest of the specifications for your program in Part 1 can be inferred from examples in Section 3.  You will notice that the program is required to display greetings surrounded with stars. You may write a separate function for that.

2    Part 2: A Library of Functions

For this part of the assignment, you are required to write and test four functions  (as you did in Assignment  1).   You need to save all functions in part2_xxxxxx.py where you replace xxxxxx by your student number.  You need to test your functions (like you did in Assignment 1) and copy/paste your tests in part2_xxxxxx.txt.  Thus, for this part you need to submit two files:  a2_part2_xxxxxx.py and a2_part2_xxxxxx.txt

2.1    min_enclosing_rectangle(radius,  x,  y) - 5 points

Computing a smallest (axis-aligned) rectangle that encloses a set of objects in the plane is a very common computational problem arising in graphics and thus game development too. Write a function, called min_enclosing_rectangle, that has 3 input parameters.  The first is a number representing a radius of a circle and the next two are two numbers representing the x- and y-coordinates of its center.  Consider the smallest axis-aligned rectangle that contains that circle.  The function should  return  the x-  and  y-coordinates  of the  bottom-left  corner  of that  rectangle.   If  radius is  a  negative  number, min_enclosing_rectangle should return None.

>>> min_enclosing_rectangle(1,1,1)

(0,  0)

>>> min_enclosing_rectangle(4.5,  10,  2)

(5.5,  -2.5)

>>> min_enclosing_rectangle(-1,  10,  2)

>>> min_enclosing_rectangle(500,  1000,  2000)

(500,  1500)

2.2    vote_percentage  (results) - 5 points

Write a function called vote_percentage that takes a string as input.   The function has one input parameter,  called  results. Your function should count the number of substrings ’yes’ in the string results and the number of substrings ’no’ in the string results, and it should return the percentage of ’yes’ (among all ’yes’ and ’no’).  (You may assume that string  results has at least one yes or no and that the only words present are yes, no and/or abstained).

Hint: you may use count method from Python’s str module/library.

>>>  vote_percentage( ' yes  yes  yes  yes  yes  abstained  abstained  yes  yes  yes  yes ' )

1.0

>>>  vote_percentage( ' yes,yes,  no,   yes,  no,  yes,  abstained,  yes,   yes,no ' )

0.6666666666666666

>>>  vote_percentage( ' abstained  no  abstained  yes  no  yes  no  yes  yes  yes  no ' )

0.5555555555555556

>>>  vote_percentage( ' no  yes  no  no  no,  yes  yes  yes  no ' )

0.4444444444444444

2.3    vote() - 5 points

If there is a vote at a meeting, there are several possible outcomes based on the number of yes and no votes  (abstains are not counted).  If all the votes are yes, then the proposal passes  "unanimously", if at least 2/3 of the votes are yes, then the proposal passes with "super majority", if at least 1/2 of the votes are yes, then the proposal passes by "simple majority", and otherwise it fails. Write a function called vote that asks a user to enter all yes-s and no-s and abstained-s and then press enter.   The function then prints the outcome of the vote.   You solution must involve making a call to function vote__percentage (You may assume that the user will enter at least one yes or no and that the only words present are yes, no and/or abstained)

>>>  vote()

Enter  the  yes,  no,  abstained  votes  one  by  one  and  then  press  enter:

yes  yes  yes  yes  yes  abstained  abstained  yes  yes  yes  yes

proposal  passes  unanimously >>>  vote()

Enter  the  yes,  no,  abstained  votes  one  by  one  and  then  press  enter:

yes,yes,  no,   yes,  no,  yes,  abstained,  yes,   yes,no

proposal  passes  with  super majority >>>  vote()

Enter  the  yes,  no,  abstained  votes  one  by  one  and  then  press  enter:

abstained  no  abstained  yes  no  yes  no  yes  yes  yes  no

proposal  passes  with  simple majority >>>  vote()

Enter  the  yes,  no,  abstain  votes  one  by  one  and  then  press  enter:

no  yes  no  no  no,  yes  yes  yes  no proposal  fails

2.4       l2lo(w) - 5 points

Write a function called l2lo(w) that takes a non-negative number w as input and returns a pair of numbers  (l,o) such that w  =  l  +  o/16 and l is an integer and o is a non-negative number smaller than 16.  Note that the solution l and o are unique.

>>>  l2lo(7.5)

(7,  8.0)

>>>

>>>  l2lo(9.25)

(9,  4.0)

>>>



热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图