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

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

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