首页 > 编程语言 >comp9021 olygons Python

comp9021 olygons Python

时间:2024-11-11 20:19:30浏览次数:1  
标签:olygons polygons Python some number filename polys input comp9021

Assignment 2 , Trimester 3, 2024

  1. General matter

1.1. Aims. The purpose of the assignment is to:

  • design and implement an interface based on the desired behaviour of an application program;
  • practice the use of Python syntax;
  • develop problem solving skills.

1.2. Submission. Your program will be stored in a file n amed p olygons.py. A fter y ou h ave d eveloped andtested your program, upload it using Ed (unless you worked directly in Ed). Assignments can be submittedmore than once; the last version is marked. Your assignment is due by November 11, 9:00am.

1.3. Assessment. The assignment is worth 13 marks. It is going to be tested against a number of input files.For each test, the automarking script will let your program run for 30 seconds.Assignments can be submitted up to 5 days after the deadline. The maximum mark obtainable reduces by5% per full late day, for up to 5 days. Thus if students A and B hand in assignments worth 12 and 11, bothtwo days late (that is, more than 24 hours late and no more than 48 hours late), then the maximum markobtainable is 11.7, so A gets min(11.7, 11) = 11 and B gets min(11.7, 11) = 11. The outputs of your programsshould be exactly as indicated.1.4. Reminder on plagiarism policy. You are permitted, indeed encouraged, to discuss ways to solve theassignment with other people. Such discussions must be in terms of algorithms, not code. But you mustimplement the solution on your own. Submissions are routinely scanned for similarities that occur when studentscopy and modify other people’s work, or work very closely together on a single implementation. Severe penaltiesapply.

  1. General presentationYou will design and implement a program that will
  • extract and analyse the various characteristics of (simple) polygons, their contours being coded andstored in a file, and

either display those characteristics: perimeter, area, convexity, number of rotations that keep thepolygon invariant, and depth (the length of the longest chain of enclosing polygons)or output some Latex code, to be stored in a file, from which a pictorialrepresentation of thepolygons can be produced, coloured in a way which is proportional to their area.

Call encoding any 2-dimensional grid of size between between 2 × 2 and 50 × 50 (both dimensions can bedifferent) all of whose elements are either 0 or 1.Call neighbour of a member m of an encoding any of the at most eight members of the grid whose value is 1and each of both indexes differs from m’s corresponding index by at most 1. Given a particular encoding, weinductively define for all natural numbers d the set of polygons of depth d (for this encoding) as follows. Let anatural number d be given, and suppose that for all d 0 < d, the set of polygons of depth d 0 has been defined.Change in the encoding all 1’s that determine those polygons to 0. Then the set of polygons of depth d isdefined as the set of polygons which can be obtained from that encoding by connecting 1’s with some of theirneighbours in such a way that we obtain a maximal polygon (that is, a polygon which is not included in anyother polygon obtained from that encoding by connecting 1’s with some of their neighbours).12>>> polys.display()The effect of executing polys.display() is to produce a file named polys_4.tex that can be given asargument to pdflatex to produce a file named polys_4.pdf that views as follows.20

  1. Detailed description

4.1. Input. The input is expected to consist of ydim lines of xdim 0’s and 1’s, where xdim and ydim are atleast equal to 2 and at most equal to 50, with possibly lines consisting of spaces only that will be ignored andwith possibly spaces anywhere on the lines with digits. If n isthe x th digit of the y th line with digits, with

0 x < xdim and 0 y < ydim , then n is to be associated with a point situated x × 0.4 cm to the right andy × 0.4 cm below an origin4.2. Output. Consider executing from the Python prompt the statement from polygons import * followedby the statement polys = Polygons(some_filename). In case some_filename does not exist in the workingdirectory, then Python will raise a FileNotFoundError exception, that does not need to be caught. Assumthat some_filename does exist (in the working directory). If the input is incorrect in that it does not containonly 0’s and 1’a besides spaces, or in that it contains either too few or too manylines of digits, or in thasome line of digits contains too many or too few digits, or in that two of its lines of digits do not contain thesame number of digits, then the effect of executing polys = Polygons(some_filename) should be to generate

a PolygonsError exception that reads

Traceback (most recent call last):

...polygons.PolygonsError: Incorrect input.If the previous conditions hold but it is not possible to use all 1’s in the input and make them the contoursof polygons of depth d, for any natural number d, as defined in the general presentation, then the effect ofexecuting polys = Polygons(some_filename) should be to generate a PolygonsError exception that readsTraceback (most recent call last):

...polygons.PolygonsError: Cannot get polygons代写comp9021 olygons   Python   as expected.If the input is correct and it is possible to use all 1’s in the input and make them the contours of polygonsof depth d, for any natural number d, as defined in the general presentation, then executing the statementpolys = Polygons(some_filename) followed by polys.analyse() should have the effect of outputting a firstline that readsPolygon N:with N an appropriate integer at least equal to 1 to refer to the N’th polygon listed in the order of polygons

highest point from smallest value of y to largest value of y, and for a given value of y, from smallest valueof x to largest value of x, a second line that reads one ofPerimeter: a + b*sqrt(.32)Perimeter: aPerimeter: b*sqrt(.32)

with a an appropriate strictly positive floating point number with 1 digit after the decimal point and b anappropriate strictly positive integer, a third line that readsArea:with a an appropriate floating point number with 2 digits after the decimal point, a fourth line that reads oneofConvex: yesConvex: nofifth line that readsNb of invariant rotations: N21with N an appropriate integer at least equal to 1, and a sixth line that readsDepth: Nwith N an appropriate positive integer (possibly 0)Pay attention to the expected format, including spaces.If the input is correct and it is possible to use all 1’s in the input and make them the contours of polygons of depth d, for any natural number d, as defined in the general presentation, then executing the statement polys = Polygons(some_filename) followed by .display() should have the effect of producing a file named some_filename.tex that can be given as argument to pdflatex to generate a file namesome_filename.pdf. The provided examples will show you what some_filename.tex should contain.

  • Polygons are drawn from lowest to highest depth, and for a given depth, the same ordering as previouslydescribed is used.
  • The point that determines the polygon index is used as a starting point in drawing the line segmentsthat make up the polygon, in a clockwise manner.
  • A polygons’s colour is determined by its area. The largest polygons are yellow. The smallest polygonsare orange. Polygons in-between mix orange and yellow in proportion of their area. For instance, apolygon whose size is 25% the difference of the size between the largest and the smallest polygon willreceive 25% of orange (and 75% of yellow). That proportion is computed as an integer. When the valueis not an integer, it is rounded to the closest integer, with values of the form z.5 rounded up to z + 1.Pay attention to the expected format, including spaces and blank lines. Lines that start with % are comments.The output of your program redirected to a file will be compared with the expected output saved in a file (of adifferent name of course) using the diff command. For yourprogram to pass the associated test, diff shouldsilently exit, which requires that the contents of both files be absolutely identical, character for character,including spaces and blank lines. Check your program on the provided examples using the associated .tex files,renaming them as they have the names of the files expected to be generated by your program.

标签:olygons,polygons,Python,some,number,filename,polys,input,comp9021
From: https://www.cnblogs.com/comp9321/p/18540491

相关文章

  • python算法之最low三人组之一——————选择排序
    之前讲过了冒泡排序,我们再聊一聊最low三人组中的选择排序,选择排序的基本思想是:遍历整个序列,选取其中一个最小的数取出来,然后再次遍历除了刚刚选出来的最小的数的序列中最小的数现在让我们看看代码实现importrandomdefselect_sort(li):new_li=[]foriinrange(l......
  • python毕设车辆维修管理系统程序+论文
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容一、选题背景关于车辆维修管理系统的研究,现有研究多集中在传统维修流程的信息化实现方面,例如用户信息管理、车辆基本信息维护等通用功能的实现 [1......
  • Python小白学习教程从入门到入坑------第二十九课 访问模式(语法进阶)
    目录一、访问模式1.1 r1.2 w1.3 + 1.3.1r+1.3.2w+1.3.3a+1.4a一、访问模式模式可做操作若文件不存在是否覆盖r只能读报错-r+可读可写报错是w只能写创建是w+可读可写创建是a只能写创建否,追加写a+可读可写创建否,追加写1.1 rr:只读模式(默认模式),文件......
  • Python小白学习教程从入门到入坑------第三十课 文件定位操作(语法进阶)
    一、文件指针python中严格来说没有指针这个说法,但有指针这个用法的体现。指针概念常用于c语言、c++语言中在Python的文件操作中,文件指针(也称为文件游标或文件句柄的位置)是一个内部标记,它指示了当前文件操作的读写位置,文件指针在打开文件时初始化,并随着文件的读写操作而移动......
  • python毕设艺术团管理系统程序+论文
    本系统(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。系统程序文件列表开题报告内容一、选题背景关于艺术团管理系统的研究,现有研究主要以通用的社团管理系统为主,专门针对艺术团这一特殊团体的管理系统研究较少。在国内外,社团管理系......
  • python之函数
    一、什么是函数定义:函数是组织好,可重复使用,用来实现单一,或关联功能的代码段二、pycharm中的表结构项目,包(init)或目录,py文件,py文件包含多个函数或类等三、函数的有哪些优点?1、降低代码冗余2、增加代码的复用性,提高开发效率3、提高程序的拓展性4、封装:就是把代码片段放在函......
  • 数学与统计计算:Python math 与 statistics库基础教程
    数学与统计计算:Pythonmath与statistics库基础教程在数据分析、机器学习和科学计算中,数学和统计学是两个至关重要的基础。Python提供了强大的内置库math和statistics,可以帮助我们快速、方便地完成常见的数学和统计计算。本篇博客将介绍math和statistics库中的基......
  • 管理 Python 环境和依赖关系的工具 venv、virtualenv、pipenv 、poetry 、 miniforge
    管理Python环境和依赖关系的工具venv、virtualenv、pipenv、poetry、miniforge和anaconda的区别venv、virtualenv、pipenv、Poetry、Miniforge和Anaconda都是用于管理Python环境和依赖关系的工具,但它们在功能和使用场景上有一些显著的区别。以下是它们的主要区别:v......
  • 使用wxpython开发跨平台桌面应用,基类列表窗体的抽象封装处理
    在开发一套系统框架的时候,除了关注实现系统的功能实现外,我们对于系统的各个方面都是应该精益求精,以最少的编码做最好的事情,在开发的各个层次上,包括前端后端,界面处理、后端处理、常用辅助类、控件封装等等方面,我们都可以通过抽象、重用等方式,实现代码的优化、简化,以期达到快速开发......
  • Python之函数5.1
    函数:一、什么是函数定义:函数是组织好,可重复使用,用来实现单一,或关联功能的代码段二、pycharm中的表结构项目,包(init)或目录,py文件,py文件包含多个函数或类等三、函数的有哪些优点?1、降低代码冗余2、增加代码的复用性,提高开发效率3、提高程序的拓展性4、封装:就是把代码片段......