聯系方式

您當前位置:首頁 >> Python編程Python編程

日期:2019-06-02 11:01

159.171 - Assignment 3 – 2019

Worth: 20% of final mark

Due date: 6pm Friday, May 31st

For all two programs:

use meaningful names for variables and functions.

add any comments you think will help explain what your program's doing

Question 1: Random Real Estate Advertisement Generator (10 marks)

Write a program that reads in a file of properties and produces random but realistic advertisements,

according to the rules specified on the next page.

Here are two examples:

*** Your Brand New Home ***

Spacious 2 bedroom home in Hokowhitu.

Would suit a retired couple.

Close to hospital.

Price $320,000.

All enquires to John on 021-027-1234.

*** Make it yours today! ***

*** Your New Family Home ***

Wonderful 3 bedroom home in Terrace.

Would suit a professional couple.

Close to motorway.

Price Auction.

All enquires to Joe on 183-007-1239.

*** Make it yours today! ***

It does this by randomly choosing properties that meet certain criteria.

The basic structure of your advertisement is below, where parts in <...> are words/phrases to

be randomly selected from the lists:

*** Your <description> Home ***

<adjective> <no of bedrooms> bedroom home in <suburb>.

Would suit <type of owner>.

Close to <amenities close by>.

Price <price>.

All enquires to <agent name> on <agent phone>.

*** Make it yours today! ***

Randomly choose an item from the following lists to fill in the description, adjective, and type of

owner, but the word selected for description must meet the rules specified on the next page.

description = ['First', 'Dream', 'New Family', 'Brand New']

adjective = ['Wonderful', 'Sunny', 'Spacious', 'Secluded']

type_of_owner = ['a couple', 'a family', 'a retired couple',

‘a large family', 'a professional couple']

159.171 Assignment 3 Page 2 of 6

Randomly choose a property from properties.txt (download it on Stream) to fill in the number

of bedrooms, suburb, amenities close by, price, agent name and agent phone based on the

selected type of owner and the rules specified in the below table.

In properties.txt, each line is the detailed information of a property: each part is separated by a

hyphen (“-”); nearby amenities are connected by a colon (“:”). The following is an example of a

property:

no of bathrooms

Albany-3-2-$670000-great schools:bus station:shopping centre-John-0234513456

suburb price amenities close by agent name agent phone


no of bedrooms

The detailed information of this property is:

suburb: Albany

no of bedrooms: 3

no of bathrooms: 2

price: $670,000

amenities close by: great schools, bus station, shopping centre

agent name: John

agent phone: 023-451-3456

According to the rules specified in the above table, this property is suitable for a family owner or

a professional couple owner. For other types of owner (a couple, a retired couple, and a big

family), this property is unable to meet their criteria.

159.171 Assignment 3 Page 3 of 6

Commands

Make the following commands available using a menu and prompt for a command. The commands

can be upper or lower case (e.g. e or E) or either. It'll be easier if you implement the commands in

order (L first ...)

CMD Effect

L Load properties.txt from disk to form a property list.

T Test: display the first two properties from the property list to make sure they've

been loaded.

E

Easy advertisement: display an advertisement -- a randomly selected property

from the property list and randomly selected words from description, adjective

and type_of_owner lists.

R

Real advertisement: generate & display a real estate advertisement conforming

to the rules specified on the previous page. If the wordlists haven't been loaded,

display an error message.

S

Search: Prompt for a type of owner, and then search for all properties that meet

this type of owner’s criteria specified on the previous page. Next sort these

properties by price. Finally produce & display three advertisements: one is for a

property with the lowest price; second is for a property with the highest price;

third is for a property by Auction. Search case-independently. If the search string

is empty, exit the search and redisplay the menu.

Q Quit the program.

For full marks

The sentences in the advertisement should be capitalised correctly and have a trailing full

stop.

Words for description, suburb, and name should be capitalised.

Price has two types of value: one is amount, another is Auction. The format for price is

$11,111,111 or Auction.

The formats for phone should be 11-111-1111.

159.171 Assignment 3 Page 4 of 6

Question 2: Student Profiles (10 marks)

Using a dictionary indexed by student ID, write a simple Student Profiles that lets you save

these profile details.

Here student ID is composed of 7 digital numbers and always starts with 192. It should be

generated automatically. Each student’s ID should be unique.

The usercode is composed of the first letter of the student’s first name and the student’s last

name, if there are duplicates, append a number to distinguish them. Each student’s usercode is

unique. For example,

Student Name Usercode

Xing Chen xchen

Alan Wang awang

Xiaoping Chen xchen1

John Truter jtruter

Xiaoai Chen xchen2

When adding Xiaoping Chen to the Student Profiles, xchen already exists, so this

student’s usercode becomes xchen1.

While Xiaoai Chen is added, there already have two xchen in the Profiles, so xchen2 is

this student’s usercode.

Once the name of a student is known, the program should automatically generate this

student’s usercode.

Each dictionary entry contains a dictionary of the details of that student, so

students['1920001'] # will return the dictionary that contains details of

a student whose ID is 1920001,

and

profiles = students['1920001']

address = profiles['address']

or simply

address = profiles['1920001']['address']

will return the address of the student whose ID is 1920001.

159.171 Assignment 3 Page 5 of 6

The program first displays a menu (something like that shown below) and carries out the

appropriate action depending on which letter the user types, and then redisplays the menu:

find prompt for a usercode or student ID, then search for the name, address, email

and phone number of the student with this usercode or ID in Student Profiles

and display their details. Make the search is case-insensitive.

add prompt separately for each of name, address, email, and phone-no. Then

automatically generate this student’s ID and usercode and save all of these

fields into a data structure. A dictionary is recommended but a list will also

work.

delete prompt for a usercode or student ID, then find and display the related entry.

Ask the user if this is the correct one to be deleted. If they reply "yes", delete

it.

modify prompt for a usercode or student ID, then prompt for a field, e.g. name,

address, email, or phone-no. Next prompt for a new value for the field.

Display the student’s detail. Ask the user if this is the correct student and is

the right field to be modified. If they reply "yes", replace this field with the

new value.

list all As expected list all the entries, numbered sequentially. Display all the fields

and format them for easy reading. Down and cross layouts are shown below.

Down

ID Name Usercode Address Email Phone

1 1920001 Sue Chen schen 104 Broad Way [email protected] 021-334-2312

2 1920002 Robert Lee rlee 25 Ritzherbert Ave [email protected] 021-489-8865

The Student Profiles - Getting Started:

get the menu going and then create a function for each of list-all, add, ... Initially, simply

put a print inside each function, e.g. for the addEntry function, put print("You called

ADD"). You can test each command – they'll simply print out a message.

using an assignment statement, manually create a tiny Student Profiles containing two or

three entries

get the list-all command going. You can use this to view your manually created Student

Profiles and effects of the later commands

then work on add, find, delete and modify

to abort the add command (and find/delete/modify), simply enter an empty string.

IMPORTANT:

make sure that there are no duplicates for Student IDs and Usercodes,

make sure that you use functions, usually one for each of the commands. You can of

course, create any additional functions that you think will help to simplify or clarify your

code.

Optional (you can get full marks without doing this): you could try adding a s (search)

command that searches for and displays all entries that have the search string in any of the fields

(not just the ID or usercode).

What and how to submit

How: ALL submissions must be via Stream (not email) using the Assignment 2 submission link.

What: Submit your Python programs, each named with .py extensions. You should have three .py

files to submit, one for each question.

Do not submit Word documents (.doc or .docx) or .zip or .rar files.

Check:

that your files have a .py extension

that all programs display your name and your Massey Student ID number when starting.


版權所有:編程輔導網 2018 All Rights Reserved 聯系方式:QQ:99515681 電子信箱:[email protected]
免責聲明:本站部分內容從網絡整理而來,只供參考!如有版權問題可聯系本站刪除。

25选5一等奖多少钱