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
讲解:CSC 120、Computer Programming、Python、PythonC/C++|Java
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 本文转载自知乎 作者:季子乌 笔记版权归笔记作者所有 其中英文语句取自:英语流利说-懂你英语 ——————————...