Instructions
Objective
Write a python homework Write a python homework program to create data procession system.
Requirements and Specifications
Introduction
Higher/Lower is a single-player data procession system that uses a standard shuffled deck of playing cards from which a number of cards have been dealt face-down. The object of the game is to turn over the first card revealing its value and then to predict whether the next card to be turned over is higher or lower in value than the previous. For example, if the game consists of 5 cards, the initial state of play might be as shown below, where the 4♥ is visible and the remaining 4 cards are face-down from left-to-right.
4♥ ! ! ! ! Your score = 0
The player is now invited to say whether they think that the next card will be higher or lower than a 4. In this instance they might guess “higher” and the next card is revealed as the 9♣. As the user’s guess was correct, the game continues.
4♥ 9♣ ! ! ! Correct guess, your score = 1
This time the user guesses that the next card will be lower than a 9, but when the card is turned over, it is revealed to be the 10♠. As they have guessed incorrectly, the game is over, and their final score is confirmed.
4♥ 9♣ 10♠ ! ! Incorrect guess, your final score = 1
If the player successfully turns over all cards with correct guesses, the game automatically ends.
Where consecutive cards are the same value, for example Q♥ followed by Q♣, then the player is guaranteed to lose as the second Queen is neither higher nor lower than the first one. In this game, the Ace is the highest value available so that the values in order from lowest to highest are 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A.& Note that your application will be a pure text version – with keyboard input. There is no requirement for a graphical or mouse-based solution.
Required Functionality
There are 7 levels
Level 1: The facilities to create a new game are present and the game can be set up in its initial state, with 5 cards dealt from a shuffled deck, one of which is shown face-up (i.e. its value is on display) with the remaining cards face-down. You can use any appropriate text representation for the cards.
Level 2: The basic game mechanism is in place. Users can select “higher” or “lower” when each card is displayed, and the next card is revealed or the game ends depending on their choice.
Level 3: A full playable game is available. The application is able to prompt the player when the game is won (all cards successfully guessed) or lost (a wrong guess has been made).
Level 4: Before the game begins, the user is prompted for the number of cards to be used. For example, if the user chooses 10 cards, then one is displayed face up and 9 correct guesses need to be made for a winning game.
Level 5: The user can “stick” by declining to guess either “higher” or “lower”. In this case the game is won, and the user is awarded a score according to the number of correct guesses made so far. A high-score table is displayed after each game showing the top 5 winning performances so far.
Level 6: On completion of a game (whether the player has won or lost) the application is able to replay the game guess by guess, with the user prompting each replayedmove by a keypress.
Level 7: The application is able to play a complete game in “demonstration mode”, where all 52 shuffled cards are dealt. In demonstration mode, the user’s only input is topress a key to begin the next move and the demonstration continues until an incorrect guess is made or all 52 cards have been successfully revealed. A separate “Demonstration” high score table should show the computer’s top 5 demonstration performances.
Deliverables
The deliverables for this assessment are as follows:
- “HigherLower” Application – A Zip file containing all code developed for the application. The easiest way to create this is to Zip the contents of the src folder of your python project. Each python file should also be provided as a PDF document. Please include comments throughout code.
- Design and Development Document – A PDF document that contains a written account of the design and development decisions made during the development of your application. You should provide evidence of your consideration of data structures used and algorithms developed, with justification for your decisions and rejection of alternatives.
- Testing Document – A PDF document that describes your testing regime with details of any test classes developed. This document should also describe steps you have taken to ensure the security of your implementation.
Please do not use advanced method of coding, just amateur level, Thank you.
Source Code
"""
@author: YOUR NAME
@collaborators: None
"""
from typing import List, Tuple
def readInput(file) -> Tuple[int,List[float]]:
"""This function receives a file object and reads its content
Args:
file (file object): Opened file object in read mode
Returns:
int: ID of the rain gauge
list: List of floating point values with the daily rain gauge data
"""
# Read all lines from line
lines = file.readlines()
# The first line contains the info, so skip it
lines.pop(0)
# The second line contains the id. We have to split that line and take the second element
ID: int = int(lines.pop(0).split(' ')[1])
# Third and fourth lines contains latitude and longitude. Since we don't need these values
# we can just skip these two lines
lines.pop(0)
lines.pop(0)
# The remaining lines contains the data
# Create the list to store the values
data: List[float] = list()
# Now, loop through the rest of the lines
for line in lines:
record = float(line) # Convert to float
data.append(float(record)) # Append to the list
# Return
return ID, data
def calcAverage(data) -> Tuple[int, float]:
"""Calculate the number of "No Data" points and average of valid values
Args:
data (List[float]): Records from weather station
Returns:
int: Number of "No Data" records
float: Average of all valid records
"""
# Define a variable to count the number of "No Data" records
n_nodata: int = 0
# Define a variable to store the average of the valid records
average: float = 0.0
# Now, loop through the records
for record in data:
# If record if valid, add to average
if record >= 0:
average += record
else: # If not, it is because it has a value of -9999.0
n_nodata += 1
# Finally, divide the average variable by the number of valid records
# The number of valid records is equal to the length of data minus n_nodata
average = average / (len(data) - n_nodata)
# Now, return
return n_nodata, average
def main():
""" This function contains the main functionality of the program
Here, we ask to user for the name of the files, do all calculations
and finally display the results
"""
# First, get the name of the first file
filename1 = input('What is the first rain gauge data input file? ')
# Ask for second file
filename2 = input('What is the second rain gauge data input file? ')
# Now, open both files
file1 = open(filename1, 'r')
file2 = open(filename2, 'r')
# Read input from both files
ID1, data1 = readInput(file1)
ID2, data2 = readInput(file2)
# Calculate number of "No Data" and average for each file
n_nodata1, average1 = calcAverage(data1)
n_nodata2, average2 = calcAverage(data2)
# Now, print
print("ID = {0}, Average Rainfall = {1:.2f} mm, No Data Values = {2}".format(ID1, average1, n_nodata1))
print("ID = {0}, Average Rainfall = {1:.2f} mm, No Data Values = {2}".format(ID2, average2, n_nodata2))
# Now, print the one with the highest average
highestAvgID = ID1 # Set by default that the Weather Station 1 has the highest avg
if average2 > average1: # Check if station 2 has higher avg
highestAvgID = ID2
# Print
print("Weather Station with ID {0} had the highest average rainfall".format(highestAvgID))
if __name__ == '__main__':
main()
Similar Samples
Explore Our Sample Solutions At Programming Homework Help, we provide comprehensive sample assignments to help you overcome programming challenges. Our expertly crafted examples clarify complex concepts and enhance your coding skills. Visit our samples section to see how we can support your learning journey.
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python