**Click once—type in course code—do not use return key** (2004) COMP 1039 Problem Solving and Programming Programming Assignment 2 School of Computer and Information Science The University of South...

1 answer below »
review pls


**Click once—type in course code—do not use return key** (2004) COMP 1039 Problem Solving and Programming Programming Assignment 2 School of Computer and Information Science The University of South Australia May, 2021 2 of 32 Contents Introduction Assignment Overview Graduate Qualities Part I Specification  Practical Requirements (Part I)  Stages (Part I) Part II Specification  Practical Requirements (Part II)  Stages (Part II) Submission Details Extensions and Late Submissions Academic Misconduct Marking Criteria Sample Output – Part I Sample Output – Part II Useful Built-In Python Functions – required for part II 3 of 32 INTRODUCTION This document describes the second assignment for Problem Solving and Programming. The assignment is intended to provide you with the opportunity to put into practice what you have learnt in the course by applying your knowledge and skills to the implementation of a Python module (that contains functions that operate on lists) and a program that will maintain information on players playing blackjack (dice) against the computer. This assignment is an individual task that will require an individual submission. You will be required to submit your work via learnonline before Tuesday 15 June (swot vac), 9:00 am. This document is a kind of specification of the required end product that will be generated by implementing the assignment. Like many specifications, it is written in English and hence will contain some imperfectly specified parts. Please make sure you seek clarification if you are not clear on any aspect of this assignment. ASSIGNMENT OVERVIEW There are two parts to this assignment: Part I: Writing a Python Module (list manipulation functions) You are required to implement a Python module that contains functions that manipulate lists. Please ensure that you read sections titled 'Part I specification' below for further details. Part II: Manage player information You are required to write a Python program that will manage player information. The program will allow players to play blackjack (dice version) against the computer and will maintain information on players. Player information will be stored in a text file that will be read in when the program commences. Once the initial player information has been read in from the file, the program should allow the user to interactively query and manipulate the player information as well as play blackjack against the computer. Please ensure that you read sections titled 'Part II specification' below for further details. Please ensure that you read sections titled ‘Part I Specification’ and ‘Part II Specification’ below for further details. 4 of 32 GRADUATE QUALITIES By undertaking this assessment, you will progress in developing the qualities of a University of South Australia graduate. The Graduate qualities being assessed by this assignment are:  The ability to demonstrate and apply a body of knowledge (GQ1) gained from the lectures, workshops, practicals and readings. This is demonstrated in your ability to apply problem solving and programming theory to a practical situation.  The development of skills required for lifelong learning (GQ2), by searching for information and learning to use and understand the resources provided (Python standard library, lectures, workshops, practical exercises, etc); in order to complete a programming exercise.  The ability to effectively problem solve (GQ3) using Python to complete the programming problem. Effective problem solving is demonstrated by the ability to understand what is required, utilise the relevant information from lectures, workshops and practical work, write Python code, and evaluate the effectiveness of the code by testing it.  The ability to work autonomously (GQ4) in order to complete the task.  The use of communication skills (GQ6) by producing code that has been properly formatted; and writing adequate, concise and clear comments.  The application of international standards (GQ7) by making sure your solution conforms to the standards presented in the Python Style Guide slides (available on the course website). 5 of 32 PART I SPECIFICATION – WRITING A PYTHON MODULE (LIST MANIPULATION FUNCTIONS) You are required to write a list_function.py module (containing only the functions listed below). This file is provided for you (on the course website) however, you will need to modify this file by writing code that implements the functions listed below. Please read the slides on modules available on the course website if you would like more information on modules. You are required to implement a Python module containing the following functions: 1. Write a function called length(my_list) that takes a list as a parameter and returns the length of the list. You must use a loop in your solution. You must not use built-in functions, list methods or string methods in your solution. 2. Write a function called to_string(my_list, sep=', ') that takes a list and a separator value as parameters and returns the string representation of the list (separated by the separator value) in the following form: item1, item2, item3, item4 The separator value must be a default argument. i.e. sep=', ' You must use a loop in your solution. You must not use built-in functions (other than the range() and str() functions), slice expressions, list methods or string methods in your solution. You may use the concatenation (+) operator to build the string. You must return a string from this function. 3. Write a function called find(my_list, value) that takes a list, and a value as parameters. The function searches for the value in the list and returns the index at which the first occurrence of value is found in the list. The function returns -1 if the value is not found in the list. 4. Write a function called insert_value(my_list, value, insert_position) that takes a list, a value and an insert_position as parameters. The function returns a copy of the list with the value inserted into the list (my_list) at the index specified by insert_position. Check for the insert_position value exceeding the list (my_list) bounds. If the insert_position is greater than the length of the list, insert the value at the end of the list. If the insert_position is less than or equal to zero, insert the value at the start of the list. You must use a loop(s) in your solution. You may make use of the list_name.append(item) method in order to build the new list. You must not use built-in functions (other than the range() function), slice expressions, list methods (other than the append() method) or string methods in your solution. 5. Write a function called remove_value(my_list, remove_position) that takes a list and a remove_position as parameters. The function returns a copy of the list with the item at the index specified by remove_position, removed from the list. Check for the remove_position value exceeding the list (my_list) bounds. If the remove_position is greater than the length of the list, remove the item at the end of the list. If the remove_position is less than or equal to zero, remove the item stored at the start of the list. You must use a loop in your solution. You may make use of the list_name.append(item) method in order to build the new list. You must not use built-in functions (other than the range() function), slice expressions, list methods (other than the append() method) or string methods in your solution. 6. Write a function called reverse(my_list, number=-1) that takes a list and a number as parameters. The function returns a copy of the list with the first number of items reversed. The number parameter must be a default argument. If the default argument for number is given in the function call, only the first number of items are reversed. If the default argument for number is not provided in the function call, then the entire list is reversed. Check for the number value exceeding the list bounds (i.e. is greater than the length of the list). If the number value exceeds the list bounds, then make the number value the length of the list (i.e. the entire list is reversed). If the number value entered is less than two, then return a copy of the list with no items reversed. You must use a loop(s) in your solution. You may make use of the list_name.append(item) method in order to build the new list. You must not use built-in functions (other than the range() function), slice expressions, list methods (other than the append() method) or string methods in your solution. 6 of 32 Reverse example: a) numList = [1, 2, 3, 4, 5, 6, 7] number = 4 The call to reverse(numList, number) should return the new list [4, 3, 2, 1, 5, 6, 7]. b) numList = [1, 2, 3, 4, 5, 6, 7] The call to reverse(numList) should return the new list [7, 6, 5, 4, 3, 2, 1]. Please note: You must test your functions to ensure that they are working correctly. So you do not have to write your own test file, one has been provided for you. The assign2_partI_test_file.py file is a test file that contains code that calls the functions contained in the list_function.py module. Please do not modify the test file. 7 of 32 PRACTICAL REQUIREMENTS (PART I) It is recommended that you develop this part of the assignment in the suggested stages. It is expected that your solution WILL include the use of:  The supplied list_function.py module (containing the functions listed below). This is provided for you – you will need to
Answered 1 days AfterJun 12, 2021

Answer To: **Click once—type in course code—do not use return key** (2004) COMP 1039 Problem Solving and...

Shashank answered on Jun 13 2021
134 Votes
Part2/blackjack.py
#
# PSP Assignment 2 - Provided module blackjack.py (for part II).
#
# File: blackjack.py
#
# Description: Play one game of blackJack(dice) against the computer.
#
# DO NOT modify this file.
#
import random
# Define BlackJack constants.
SCORE = 21
PLAYER_MIN_SCORE = 15
DEALER_MIN_SCORE = 17
MAX = 11
#
# Function to play one game of blackJack(dice) against the computer.
# Parameters: no parameters
# Returns: result of game - 3 for win, 1 for a draw, 0 for a loss.
#
def play_one_game():
print('\n
\n---------------------- START GAME ----------------------')
# Roll player's hand.
player_die1 = random.randint(1,MAX)
player_die2 = random.randint(1,MAX)
# Roll computer's hand (only one die).
comp_die1 = random.randint(1,MAX)
comp_die2 = random.randint(1,MAX)
# Work out current hand totals.
player_total = player_die1 + player_die2
comp_total = comp_die1 + comp_die2
# Display player's and dealer's hand - only one die so player does not know dealer's hand.
print('| Dealer\'s hand is:', comp_die1)
print('| Player\'s hand is:', player_die1)
score = 0
# Check for BlackJack on first roll.
if player_total == SCORE and comp_total == SCORE:
print('| *** Blackjack --')
print('|\n| Dealer\'s hand is:', comp_die1, '+', comp_die2, '=', comp_total)
print('| Player\'s hand is:', player_die1, '+', player_die2, '=', player_total)
print('|\n| *** Blackjack! Push - no winners! ***')
score = 1
elif player_total == SCORE:
print('|\n| Player\'s hand is:', player_die1, '+', player_die2, '=', player_total)
print('|\n| *** Blackjack! Player Wins! ***')
score = 3
elif comp_total == SCORE:
print('|\n| Dealer\'s hand is:', comp_die1, '+', comp_die2, '=', comp_total)
print('|\n| *** Blackjack! Dealer Wins! ***')
else:
# *** Else if neither player or dealer have Blackjack then play out hand. ***

# Display player's hand.
print('|\n| Player\'s hand is:', player_die1, '+', player_die2, '=', player_total)
# Play out player's hand - only if they don't bust on first roll.
if player_total < SCORE:
# Hit or stand?
play = input("| Please enter h or s (h = Hit, s = Stand): ")
while play != 'h' and play != 's':
play = input("| Please enter h or s (h = Hit, s = Stand): ")

while player_total < PLAYER_MIN_SCORE and play == 's':
print("|\n| Cannot stand on value less than ", PLAYER_MIN_SCORE, "!\n|", sep='')
play = input("| Please enter h or s (h = Hit, s = Stand): ")
# While player hasn't busted and player continues to 'hit'.
while player_total < SCORE and play == 'h':
player_die1 = random.randint(1,MAX)

print('| Player\'s hand is:', player_total, '+', player_die1, '=', end=' ')
player_total = player_total + player_die1
print(player_total)
if player_total < SCORE:
play = input("| Please enter h or s (h = Hit, s = Stand): ")

while play != 'h' and play != 's':
play = input("| Please enter h or s (h = Hit, s = Stand): ")

while player_total < PLAYER_MIN_SCORE and play == 's':
print("|\n| Cannot stand on value less than ", PLAYER_MIN_SCORE, "!\n|", sep='')
play = input("| Please enter h or s (h = Hit, s = Stand): ")

if player_total > SCORE:
print("| *** Player busts!")
# Play out dealer's hand.
print('|\n| Dealer\'s hand is:', comp_die1, '+', comp_die2, '=', comp_total)

while comp_total < DEALER_MIN_SCORE:

comp_die1 = random.randint(1,MAX)

print('| Dealer\'s hand is:', comp_total, '+', comp_die1, '=', end=' ')
comp_total = comp_total + comp_die1
print(comp_total)
if comp_total > SCORE:
print("| *** Dealer busts!")

# Determine winner and display to the screen.
print("|\n| *** Dealer:", comp_total, " Player:", player_total, ' - ', end=' ');
# If the player busts, or
# if the dealer is 21 or under and the dealers hand is greater than the players hand,
# then dealer wins the hand.
if ((player_total > SCORE) or (comp_total > player_total and comp_total <= SCORE)):
print("Dealer Wins! ***")

# If dealer and player hold the same point value, no one wins.
elif comp_total == player_total:
print("Push - no winners! ***")
score = 1

# Otherwise, the player wins.
else:
print("Player Wins! ***")
score = 3

print('----------------------- END GAME -----------------------\n')

# Return game score - 3 for a win, 1 for a draw and 0 for a loss.
return score
Part2/part2_emailid.py
#
# PSP Assignment 2 - Provided file (part2_emailid.py).
# Remove this and place appropriate file comments here.
#
# Modify this file to include your code solution.
#
#
# Write your code and function definitions in this file.
# Place your own comments in this file also.
#
import random
import blackjack
###import list_function
# Function...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here