姓名: 学号:
请注意以下几点:
请将你的程序调试完成后,复制粘贴到对应题目的对话框里面,然后点击末尾的生成作业文件按钮,会自动生成作业文件。请记得填写姓名和学号,生成的文件名会包含你的学号。
请使用这些浏览器来打开作业并生成作业文件:Chrome,Firefox,任何其他的Chrome内核浏览器(如QQ浏览器,360安全浏览器,搜狗浏览器,百度浏览器等等)。Microsoft Edge和Mac笔记本的Safari也支持。请注意:老版IE浏览器不支持。 如果你不能成功生成作业文件,请换一个浏览器尝试。
最后请将生成的作业文件上传到上财教学网的Canvas对应的作业提交。请注意每次作业的截止日期时间,逾期无法提交,迟交的作业扣一半的分数。
如果你想修改你的作业,请不要修改生成的txt文件。请重新填写表单然后重新生成txt文件。不要对生成的txt文件做任何操作(修改内容,修改学号,修改姓名)。
Write a program that creates a function fff() to show a # randomly distributed in those 9 blocks. The following shows an execution of the program.
41>>> fff()2# #3##4 #Since you will use the module random, please add import random at the beginning of your program so that you can use random.random() > 0.8 . The statement random.random() randomly generates a number in (0,1). Note that any number in (0,1) can be a threshold instead of 0.8 .
Write a program that creates a closure function such that it returns a geometric sequence (等比数列), input_ratio(r), and scale_factor(a). The following shows an execution of the program.
41gs3=input_ratio(3)2print(gs3(4))3#output4(4, 12, 36, 108, 324) Write a program that creates a decorator. The function to be decorated is given as follows.
21def numbers(*args):2 print(args)The following shows an execution of your program. Note that the number 4 in the last line means there are 4 numbers in the tuple. In other words, it calculates the number of arguments. Please do not simply add a sentence.
912def numbers(*args):3 print(args)4
5numbers(1,2,3,4)6#output7The numbers are:8(1,2,3,4)9There are 4 numbers.Write a program that creates a class named Food with two attributes which are name and price. Then, create two methods: one is to show the name and price, and the other is to update the price. Then, create a subclass Fruit which is a child class of the parent class Food. The class Fruit inherits the two attributes from its parent class and has its own attribute about its producing area. Then create a method of the child class to show its producing area. The following shows an execution of the program.
121food_1 = Food('Hot Dog', 15)2food_1.get_info()3food_1.update_price(20)4food_1.get_info()5#output6Hot Dog has a price of 15.7Hot Dog has a price of 20.8----------------------------------------------------------------------------9fruit_1 = Fruit('Orange', 5, 'California')10fruit_1.show_area()11#output12Orange is produced in California.Write a program that creates a class named Num to receive a sorted array of numbers without duplicates as an attribute. Create a method sip (search insert position) to receive a target value, the method return the index if the target is found in the array. If not, return the index where it would be if it were inserted in order. The following shows the execution of the function. (Do not use any build-in function or method.)
91x=Num((1,2,5,8,13,19))2print(x.sip(5))3#output425----------------------------------------------------------------------------6x=Num((1,2,5,8,13,19))7print(x.sip(15))8#output95Write a program that creates a class named Words to receive an array of strings as an attribute. Then create a method to find the longest common prefix string amongst the array of strings. The following shows an execution of the method. (Hint: find the shortest word at first.)
91x=Words(("flower","flow","flight"))2print(x.prefix())3#output4"fl"5----------------------------------------------------------------------------6y=Words(("apple","application","appendix","appointment"))7print(y.prefix())8#output9"app"