讲解:CSC 120、Computer Programming、Python、PythonC/C++|Java

CSC 120: Introduction to Computer Programming for Non-majorsSpring 2019Assignment 5Notes: For each question create a Python script with the name Question xxwhere xx is the question number. Provide your name and what program does in each script. Provide necessary comments. Once you are done, create a folder with the name Assignment-03, put allyour scripts in there, zip it, and then upload the zip file in to Canvas. Always show that your code works by using few test cases (1-3) If you are not clear about any of these steps, just ask. This must be your own work. I have already explained policies regradingplagiarism and they are in your syllabus.Question 1 (20 points) A pentagonal number is defined as n(3n–1)/2 forn = 1, 2, . . ., and so on. Therefore, the first few numbers are 1, 5, 12, 22, . . .Write a function that returns a pentagonal number for a given n ≥ 1.Write a test function that uses that to display the first 100 pentagonalnumbers with 10 numbers on each line.Question 2 (20 points) Write a fuCSC 120作业代做、代做Computer Programming作业、Python程序作业调试、代写Python室作nction that computes the sum of the digitsin a non negative integer. For example, sumDigits(234) returns 9(2 + 3 + 4). Write a test function with few test cases and show that yourfunction sumDigits works.Question 3 (20 points) Write a function with the name reverse, thatreverses a non negative integer passed to it. As an example, it shouldreturns 456 when you pass 654 as the input.Write a test function to test your reverse function.Now, write another function with the name palindrome which takes a nonnegative integer and check if it is a palindrome.Hint: You should use the reverse method you just created.Write a test function to test your palindrome function.Question 4 (20 points) Write a function to determine a number is prime.Write a test function with atleast 5 test cases to test your function.Question 5 (20 points) π can be estimated using following series.m(i) = 4(1 +(1)i+12i 1)Write a method to return m(i) for a given i and write a test function tothat displays the following approximation table转自:http://ass.3daixie.com/2019022347964134.html

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容