Describe an algorithm for a program that allows the club

Assignment Help Python Programming
Reference no: EM132357206

Question 1: Analysis and design

Comment on the type of question

This type of question provides a scenario (a problem to be solved or simulated and asks you to write the pseudocode. Structure and logic of your answer is important. Clearly show the beginning and the end of the program as well as conditional statements (if..elif..else). Use indentation to clearly identify blocks within the program.

Example question

A sports club is interested in classifying its members based on age and gender. Female members are put in group 'F' and male members are put in group 'M' unless the member is an adult - in which case they are put in group 'A' regardless of their gender. A member is considered to be an adult if he or she is 18 years of age or older.

Write a pseudocode to describe an algorithm for a program that allows the club to enter a member's name, gender and their age, and then prints out a message containing their name and the group into which they belong.

A typical example interaction with the program might look like the following:

Enter member name? Julie
Enter gender (F/M)? F
Enter age? 10

Julie has been put in group F

Get member name
Get member gender
Get age
If age>= 18
Group equals adult
Elif gender = ‘f'
Group = ‘f'
Else group = ‘m'
Print

Question 2: Selection

Comment on the type of question

Implement the algorithm in the previous question in Python programming language. The program should be syntactically complete and correct and should only use a main() function and no other.

Example question

Write a complete Python program that implements your algorithm from Question 1. The program will prompt the user to enter input data, process data and then print an appropriate message to display the member's group.

Note that you must NOT use any function other than the main() function to answer this question.

Name = input("enter name")
Gender = input("enter gender ‘F\M' ")
age = int(input("enter age"))
If age >= 18:
Group = "A"
Else:
Group = gender
Print ("name:-", name, "gander:-", gender, "age:-", age , " group:-" , group)

Question 3: Functions

Comment on the type of question

Implement the algorithm in the previous question this time utilising a function, which determines the group of the member. The interaction with the user is done from the main function.

The main function displays the necessary prompts to get member's name, gender and age; determines whether the person is an adult or not and then calls the new function to determine the group; finally, it displays the name and the group of the member. The new function takes gender and a boolean argument indicating whether the member is an adult or not (True or False) as input and returns the group (as ‘A', ‘F', or ‘M') to the calling function (ie. the main()).

Example question

Write the Python code to define a function called determineGroup() that takes two inputs (a character string gender and a boolean to indicate adult or not) and returns the group of the member (a character string). Rewrite the program from Question 2 to utilise this function. The 'input' and 'output' operations (interaction with the user) remain in the 'main' function.

Def determineGroup(gen,adult):
If adult == "true":
Group = ‘a'
Else :
Group = gen
Return group

Def main
Inputs
If age >= 18
True
Else
False
Group = determineGroup(gen, adult)

Question 4: Loops

Comment on the type of question

Modifying/extending the previous program to allow for the processing of multiple members using a while loop.

Example question

Modify your program from Question 3 to handle the processing of a number of members in the same run. The program should provide necessary prompts for entering data, the call to the function to determine the group, and displaying the group within a loop.

The loop should continue to execute until the user enters a blank name (ie the user enters nothing by pressing the Enter key when asked to supply a name).

It is assumed that function determineGroup() has already been defined and as such there is no need to show the function definition in your new program. Only the function calls need to be shown.

Def main()

Name = Input("name")

While name ! = ‘' :

Question 5: Programming Principles

Comment on the type of question

This question includes several parts of descriptive questions that relate to basic programming principles.

Example questions

(a) Why are comments used in a program? Briefly describe two types of comments.

(b) What are the advantages of modularising programs using functions

(c) Briefly describe two tools that can be used in presenting the design of a program

(d) What are the five naming rules for functions and variables in Python programming language?

(e) Describe the main stages in program development cycle

Question 6: Files and Exceptions

Comment on the type of question

Writing Python code to open a text file for reading and then processing the contents and displaying the output on the screen as well as sending the output to another text file which is opened for reading. Using exception handling to cover for situations where an error occurs during the opening, closing or processing text files. Close the file(s) after finishing with them.

Example question

(a) Write the Python code to open a text file for reading and display the output line by line on the screen.

(b) Modify the program in previous part to use exception handling to deal with the case where an error occurs during the opening of the file.

(c) Extend the program further to open another file for writing so that the output is sent to another text file as well as the screen.

Question 7: Sequences and Strings

Comment on the type of question
Given a list and/or a string object, perform a number of associated list and/or string operations and functions with and on the objects.

Example question

Consider the list below:
myList1 = [‘N', 'X', 'A', 'C', 'W', 'E']

For the following questions, assume the list starts from this state in each question. Moreover, you only need to write the line/s in Python code to do the following tasks and do not need to worry about other parts.

Write Python code to:

a) Print the 2nd and 5th elements of the list

b) Delete the 3rd element from the list

c) Find the length of the list

d) Add an element with value ‘U' at the end of the list

e) Add an element with the value ‘G' between the elements ‘X' and ‘A'

f) What is the output of the statement print(myList1.pop()) ?

g) Find the minimum and maximum elements in the list

h) Iterate through the list concatenating all elements into a single string variable s1

i) Sort the list in ascending order

j) Reverse the list

k) Concatenate a second list ‘myList2' to the list

Now consider the string given below:
myString1 = "My cat was sleeping in the room"

Write Python code to:

l) Create a list of strings consisting of words making up the string ‘myString1' and assign the result to a list variable called ‘stringList'

m) Replace the substring ‘cat' with ‘dog'

n) Specify a string slice that contains substring ‘ping'

Question 8: Classes and Objects

Comment on the type of question

Defining classes in Python, instantiating classes (creating objects) and invoking functions on objects.

Example question

(i) Define a class called ‘Person' with the following characteristics: a constructor (initialiser function); two data members ‘name' and ‘age'; one getter (accessor member function) and one setter (mutator member function) for each data member and a member function called ‘display' which prints the data members of Person objects.

(ii) Assuming that the class definition above is saved in file ‘person.py' in the same folder with the file "myFile.py' which has the ‘main' function in it, write the code to create two Person object one with name ‘Richard' and age ‘23' and the other with name ‘Janet' and age ‘19'.

(iii) Add code to the main, which will display the details of the person objects p1 and p2.

(iv) Add code to the main, which will change the name of the first person object (p1) to ‘George' and the age of the second person object (p2) to 30.

(v) Add code to the main to check the new name of the first Person (p1) and the new age of the second Person object (p2).

(vi) Add code to the class definition of Person which will allow one to set the address of the person as well as getting it and displaying it with the other details using the display member function.

Reference no: EM132357206

Questions Cloud

What would you suggest to keep employees from doing this : There are a couple ways to help prevent this piggybacking problem. What would you suggest to keep employees from doing this?
Evaluating networking options : Outline the main considerations that you need to take into account when evaluating your networking options.
Would you prefer to claim strict liability or negligence : Describe the relationship between products liability, negligence, and strict liability. If a client came to you with an injury caused by a product.
Describe a possible settlement of the hilary case : Draft a letter to the supervising attorney in which you describe a possible settlement of the Hilary Case and set out reasons why the client should accept it.
Describe an algorithm for a program that allows the club : Write a pseudocode to describe an algorithm for a program that allows the club to enter a member's name, gender and their age.
What is meant by the exception going up through the call : Does a child (sub) class have direct access to its superclass private members?
Discuss how each data source is relevant to the problem : Considering your chosen topic, prepare a one (1) page paper in which you: Discuss how each data source is relevant to the problem.
Explain the compression techniques of zero length : Briefly explain the compression techniques of zero length suppression and runlength encoding.
Why the maintenance phase of sdlc : In your own opinion, speculate why the maintenance phase of SDLC is often so much larger than the other phases.

Reviews

Write a Review

Python Programming Questions & Answers

  Define a python function that takes a list of integers

Define a Python function that takes a list of integers that are greater than or equal to 0 as input. The integers represent the "energy levels" of a set.

  Calculates the projected annual outgoing costs

Calculates the projected annual outgoing costs of running Parchment Purgatory - Describe the strategy you used to find appropriate prices for each scenario

  Write a program that prompts for the day and month of user

CPSC 1301L COMPUTER SCIENCE-Write a program that prompts for the day and month of the user's birthday and then prints a horoscope. Make up technology.

  Design a program that asks the user to enter monthly sales

Design a program that asks the user to enter the monthly sales values for six months. The program should store the monthly sales values in a list.

  Compute the price fluctuation between different weeks

Python Coding Assignment - You basically have to retrieve stock prices for like AAPL for the last 6 months then obtain the price fluctuations for each week

  Display the future day of the week using python code

Python only please. Write a program that prompts the user to enter an integer for today's day of the week

  Programming exercise - routing of telephone

programming exercise - routing of telephone callsdescriptionsome telephone operators have submitted their price lists

  Design a program that continuously accepts an authors name

Registration workers at a conference for authors of children's books have collected data about conference participants, including the number of books.

  What is a python development framework

What's a python development framework? give 3 examples python development framework used today.

  Analyse the performance of a drone

analyse the performance of a drone, first run the simulation normally - The actual route the drone finds can then be compared to this ‘perfect knowledge route'

  Calculate the average rainfall over a period of years

COMP 3140-Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. Theprogram should first ask.

  Program to solve shock-wave equation

ENGR30003 - Write your C program such that it uses the Newton-Raphson method - demonstrate your understanding of solving engineering problems

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd