Python 作业辅导

Python程序辅导 辅导Python编程作业 Assignment

python Tkinter recursively tree

Implement a program that shall recursively draw a “tree” in a Tkinter Canvas.

The program shall consist of a non-resizable 500×500 px canvas in a non-resizable window and a menu bar. The menu bar shall have one pull-down menu named “Draw” with two items named “Repaint” and “Exit”.

The “Exit” menu item, when selected, shall gracefully terminate the program.

The “Repaint” menu item, when selected, shall clear the canvas and draw a recursive tree at random position growing “up” (in the direction 90°). The initial length of the stem shall be 128 px. The tree shall have the number of cascades selected uniformly at random between 3 and 7, inclusive.

One cascade of the tree of length L, growing from the position (X,Y) in the direction D, shall consist of (see the attached file):

  1. the stem represented as a black line segment of length L originating at (X,Y) and forming the angle D degrees with the horizonta axis, and
  2. two trees of length L*0.8, growing from the end of the stem in the directions

python 答疑

问:

Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> s=”01234″
>>> s[0:1]
‘0’
>>>
字符串[:] 这种形式,也是左闭右开的区间吗?
所以
range(x,y) = [x,y] 等于数学上的 [ x, y)
答:
一般而言,无论是在python里还是其它的编程语言,range一般都是左闭右开。
不局限地python中的s[x:y],range(x,y)
像c++ STL中的begin(),end()等都是这样,end()-1才是最后一个元素。“
问:
python import copy中有 shallow copy 和 deep (recursive) copy
import copy

newobj = copy.copy(oldobj) # shallow copy
newobj = copy.deepcopy(oldobj) # deep (recursive) copy

对于dict={“string”:”string”, …} 这样的dict
shallow copy和deep (recursive) copy的结果是相同的, 都cop

polish to BNF via recrusive

  1. Implement a recursive function evalPolish(expression) that shall evaluate (calculate) an expression written in the prefix (“Polish”) notation. The expression shall be defined recursively in the Backus-Naur form (BNF):

    1. expression ::= integer_or_floating_point_number # A number is an expression; its value is the number itself
    2. expression ::= (operator, expression, expression) # A 3-element tuple of an operator and another two expressions is also an expression; its value is the operator applied to the values of the expressions
    3. operator ::= “+” | “-” | “*” | “/” # The list of supported operators; feel free to extend it

    Here is a sample expression and its evaluation:

    >>> good = ("+", ("-", 3, 1), ("*", ("/", 3, 4), 7)) # Same as

python questions

1.What is the value of the following expression:

sеt (rаngе (0, 20, 3)) & sеt (rangе (0, 20, 2))

{0, 6, 12, 18}

{0, 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18}

{3, 9, 15}

{2, 3, 4, 8, 9, 10, 14, 15, 16}

. 2.

Which operators are applicable to sets? (Check all that apply.)

+

*

&

|

^

/

in

. 3.

Which expression correctly changes the tail (the last element) of the middle item in the following

tuple:

foo=(12, [“a”, “n”, “d”, “y”], set (“andy”))

foo[1][-1] = “a”

foo[0][0] = “a”

Tuples are immutable and cannot be changed.

The tuple foo has items of different data types and is illegal.

. 4.

Which data type cannot be used as a key in a dictionary?

list

int

float

string

. 5.

Which data structures could be used instead of the following dictionary without any loss of

information and functionality, including possible modifications both of element names and their

weights?

elements = {“H” : 1, “He” : 4, “Li” : 7, “Be” : 9}

names = [“H”, “He”, “Li”, “Be”]

weights =

python csv assignment

  • Write a command-line program that reads a comma-separated (CSV) file and reports some basic statistics of the data in the file.

    The program must have the comment at the top of the program file: “I certify this submission as my own original work completed in accordance with the Suffolk University Academic Integrity Policy. ZZZ”, where ZZZ is the full name of the student.

    The program shall ask the user to enter the name of a CSV file. If the file does not exist, the program shall print the error message: “File XXX does not exist.” where XXX is the file name, as entered by the user, and exit. Use the attached file grades.csv for testing.

    The program shall read the file contents. Assume that the file has a perfect rectangular structure: each uncommented row has the same number of columns, and each column has the same number of rows. A row that begins with a pound sign # is commented and shall be i

cs112 project5

python 程序代写

Programming Project 5

This semester you will be writing a program that models elements of recognizing and creating characters. Optical character recognition is an important area of research that allows photographs or printed documents to be digitized; by doing so, these documents are made available for machine-based searching. On the flip side,http://en.wikipedia.org/wiki/CAPTCHA is a system for differentiating between humans and computers: the goal here is to generate a non-machine readable image that a human could identify. CAPTCHA helps reduce the amount of spam on the Internet.

We will implement a highly limited type of image matching, processing, and creation this semester. Rather than write this project at once, we will break the proj

cs112 project4

python作业代写

Programming Project 4

This semester you will be writing a program that models elements of recognizing and creating characters. Optical character recognition is an important area of research that allows photographs or printed documents to be digitized; by doing so, these documents are made available for machine-based searching. On the flip side,http://en.wikipedia.org/wiki/CAPTCHA is a system for differentiating between humans and computers: the goal here is to generate a non-machine readable image that a human could identify. CAPTCHA helps reduce the amount of spam on the Internet.

We will implement a highly limited type of image matching, processing, and creation this semester. Rather than write this project at once, we will break the proje

python Three-card Poker

4.1 Overview

Gambling has a long (and sordid) history on the internet. The history of computer games, however, is

quite a bit older than the internet. For this program, you will develop and code a game ofthree-card

poker. The computer (the Dealer) will play against a single human player (the Player). Your program

should present the game as described below.

4.2 Rules of Three-card Poker

The Player starts with a stake: some pre-determined amount of money ($100 in your program). A

game of Poker consists of a set of sub-games. Before beginning a sub-game, the Player must be able

to bet the ante, a pre-determined amount of money ($10 in your program). In each sub-games, both

the Player and Dealer is dealt a hand of three cards. Each can see their own cards, but not the others.

After seeing the hand, the Player must determine whether he will play or fold. If the Player folds, he

forfeits the ante: his stake is reduced by the ante amount. If the Player elects to play, then the Dealer

must either play or