Microsoft Word - List Exercises.docx Advanced List Exercises #1 Rainfall Tracker (10 points) An avid weather buff wants to track the daily rainfall over the course of a year and analyze the data. The...

1 answer below »
I need following assignments completed and need them completed inside the python coding file. Need to follow the instructions from the last code put on there. Do not edit or erase any other code that was already on there.


Microsoft Word - List Exercises.docx Advanced List Exercises #1 Rainfall Tracker (10 points) An avid weather buff wants to track the daily rainfall over the course of a year and analyze the data. The data entry is fairly simple, they will provide the month and day and the amount of rainfall on that day and your application will track that amount. I started the application for you, and thus you need to complete the following functions:  generateRainfallCalendar() – Create a calendar with entries for every day of the year initialized to zero. The array DAYS_PER_MONTH is available with the number of days in each month for a non-leap year.  setRainfall() – Fill the calendar for the day and month provided with the rainfall total  getTotalForMonth() – Compute the total rainfall for the month provided Check out the sequence of videos to help on this! https://www.youtube.com/playlist?list=PLgvXUCQxGQrz009NA1K738XEcECuE2cUe #2 Bird Watchers (10 points) A bird watcher keeps tabs on the birds they see as they wander the town each day. They have been doing this on paper, but now they want to move the system electronically and want you to replicate their system. Each new day the bird watch starts a new page in their ledger. Throughout the day, they add new entries to their ledger. By automating this process, you can dramatically speed up the process of counting the birds. I have started the code for you with the following functions:  addBirdSighting() – Add the sighting to the ledger. The ledger is a list that contains another list of sightings for each day. (Don’t forget to check if the ledger is new and thus empty!)  startNewDay() – Advance the ledger to a new day  birdsSeenEachDay() – Count the number of birds seen day and return the results as a list  printLedger() – print the entire ledger day by day to look something like the following: Day 1 .......................... ('Eagle', 'Backyard', '2-6PM') ('Eagle', 'Desert', '6-10AM') ('Crow', 'Jungle', '6-10AM') Day 2 .......................... ('Crow', 'Forest', '2-6AM') ('Hummingbird', 'Desert', '10PM-2AM') ('Finch', 'Desert', '2-6PM') ('Vulture', 'Park', '6-10AM') ('Vulture', 'Jungle', '6-10PM') Day 3 .......................... Day 4 .......................... #3 Hours Log (35 points) Through this class, you have been tracking the hours you spent each week. What if you made your job a bit easier by creating a log for tracking your hours each day? I started some code to this end and need your help in finishing it. The log should include a multidimensional list where each ‘row’ contains a week in the course and contains seven entries (e.g., a ten-week class has 10 rows of 7 entries each). To manage the log, you must complete the following functions:  createHoursLog() – Setup the log by creating the multidimensional list described above  logTime() – Update the log with the number of hours on the specified day and week  totalTimeForWeek() – Compute the hours spent working on the class for the given week  totalTimeForWeeks() – Compute the hours spent working on the class within the range of weeks  totalTimeOnWeekends() – Compute the total time spent studying on weekends through the course #4 Checkers (40 points) Creating a game is often a goal of programmers, but much of the game is not about pretty graphics but about the underlying engine. Checkers is a very simple game that aligns well with multidimensional arrays. The checkerboard is an 8x8 array, after all! Once again, I am good at starting code but need your help in finishing. This problem is tricky, so read through this entire description before you start.  initializeBoard() – Setup the checkerboard with the player’s pieces in the starting position. Checkers has two players, which you can model as 1 and 2. You should use a 0 to model empty spaces on the checkerboard. The initial setup of the board is as shown in the picture. The ‘red’ spaces are always black. The red pieces along the bottom are player 1’s, and the white pieces are player 2’s. Chess players use a numbering system similar to the one shown in this image1. Use something similar to align with the numbering system within the multidimensional list.  makeMove() – Update the board with the provided move. The caller will provide the player and their move. The move is a tuple with 4 values, the column number and row number the piece is moving from, and the column number and row number the piece is moving to. The column values are 0-7, corresponding with a-h and the row values are also 0-7, corresponding with 1-8. Your function can assume the move is valid (that is the next function’s responsibility). Make sure that you o Place the appropriate player’s token at the new location o Remove their token from the original location o If the move is a jump, remove the opposing player’s piece that was jumped  validGameMove() – This is the tricky one, determining if a move is indeed valid. The caller gives you the player and their move, and you should evaluate the board to see if that move is legal. 1 Chess players use the number 1-8 in the opposite direction, but it is always relative. It seems easier to visualize using lists the way it is drawn! The move is the same tuple as the makeMove() function. Our version of checkers only deals with the basic pieces (no kings), so you only need to worry about diagonal motion legal to that player. If a player attempts an illegal move, you should use one of the constants defined to report why the move was illegal. The expected return from this function include: o OK_MOVE = "OK" (The move is valid) o WRONG_PIECE = "This space does not contain your piece" o ONLY_2 = "You can only move a piece one space diagonally, or two when legally jumping" o PLAYER_1_UP = "Player 1 must move up" o PLAYER_2_DOWN = "Player 2 must move down" o SPACE_TAKEN = "The destination space is already taken" o JUMP_SELF = "You cannot jump your own piece" o JUMP_EMPTY = "You cannot jump an empty space" o UNKNOWN_INVALID = "Your move is not valid for an unknown reason" The last error is a placeholder and should not occur if you validate the move correctly. Take a few minutes to think about checkers and how you might determine (using a multidimensional list) if a move is valid. You can even try to code some of these ideas before looking at the list below or watching the hint video. o First, reject the move if the starting point is not the player’s piece. o Player 1 must move ‘up’ (from higher-numbered rows to lower-numbered rows) o Player 2 must move ‘down’ (from lower-numbered rows to higher-numbered rows) o Players cannot move onto a space already taken by another piece o Players cannot make any move that is more than two spaces vertically or horizontally (rows or columns) o If the player is moving just one horizontally and just one vertically, that move is OK! o A player can move two spaces horizontally and vertically only if they are jumping the other player, not if they are jumping their own piece or an empty space in the process. To help you debug your program, the top of the file includes a series of flags that turn on/off additional printing. The debugMove flag prints extra lines when True in the makeMove() function. The debugValidate does the same for validGameMove(). You can control whether the validGameMove() tests run with the runValidationTest flag. If you want to test your code using the UI make playAfterTest True. This flag does not enable a full game of checkers but allows moves up to the moveLimit. Check out these videos too to help you on this exercise:  https://www.youtube.com/watch?v=G4ycGDVcWls&list=PLgvXUCQxGQrz009NA1K738XEcECuE 2cUe&index=6  https://www.youtube.com/watch?v=tZtk75NCg_0&list=PLgvXUCQxGQrz009NA1K738XEcECuE2c Ue&index=7&t=2s
Answered 9 days AfterApr 28, 2021

Answer To: Microsoft Word - List Exercises.docx Advanced List Exercises #1 Rainfall Tracker (10 points) An avid...

Ankit answered on May 07 2021
143 Votes
birdwatchers.py
import random
def addBirdSighting(birdSighting, ledger):
'''
Add a bird sighting to the current day in the ledger
birdSighting - the sighting to add
ledger - the ledger to update
'''
ledger.append(birdSighting)
def startNewDay(ledger):
'''
Advance the ledger to start a new day of entries
ledger - the ledger to advance
'''
if len(ledger) == 0:
ledger.append("StartDay")
else:
ledger.append("NextDay")



def birdsSeenEachDay(ledger):
'''
Compute the number of birds within the ledger for each day
ledger - the ledger to
analyze
returns a list of counts, one for each day
'''
counts = []
i=0
ledger.append("LastDay")
for counts_list in ledger:
if "Day" in counts_list:
if(counts_list == "NextDay" or counts_list == "LastDay"):
counts.append(i)
i=0;
else:
i=i+1
ledger.remove("LastDay")
return counts
def printLedger(ledger):
'''
Print the sighting within the ledger, separated by the day
'''
i=1
for s in ledger:
if "Day" in s:
print("Day ", i ,"..........................")
i=i+1
else:
print(s)
#===================================================================
# Test code below DO NOT MODIFY
BIRDS = ["Finch", "Robin", "Hummingbird", "Crow", "Eagle", "Hawk", "Cardinal", "Vulture", "Phoenix", "Sparrow"]
LOCATIONS = ["Park", "Backyard", "Skyscraper", "Forest", "Jungle", "Roadside", "Cage", "Sky", "Desert"]
TIME_OF_DAY = ["6-10AM", "10AM-2PM", "2-6PM", "6-10PM", "10PM-2AM", "2-6AM"]
def generateSighting():
return BIRDS[random.randrange(len(BIRDS))], \
LOCATIONS[random.randrange(len(LOCATIONS))], \
TIME_OF_DAY[random.randrange(len(TIME_OF_DAY))]
def testLedger():
ledger = []
dayCount = []
numberOfDays = random.randint(4, 6)
print("The test cases will generate", numberOfDays, "days")
for day in range(numberOfDays):
startNewDay(ledger)
numberOfSightings = random.randint(0, 5)
dayCount.append(numberOfSightings)
print("Day", day + 1, "will contain", numberOfSightings, "sightings")
for count in range(numberOfSightings):
sighting = generateSighting()
addBirdSighting(sighting, ledger)
counts = birdsSeenEachDay(ledger)
if counts != dayCount:
print("birdsSeenEachDay() Failed: Your code returned", counts, "but I expected", dayCount)
else:
print("birdsSeenEachDay() Passed!")
printLedger(ledger)
# Only run this code below if this is called as the main, not imported
if __name__ == '__main__':
testLedger()
checkers.py
debugMove = False # Flip to True to see print statements to help in debugging makeMove()
runValidationTests = True # Flip to True if you are completing the validGameMove() function
debugValidate = False # Flip to True to see print statements to help in debugging validGameMove()
playAfterTest = True # Flip to True to use the User Interface to make test moves
moveLimit = 10 # Set for the maximum number of moves in a game (Hit Control-C to quit any game)
# These are the success and error messages returned by validGameMove()
OK_MOVE = "OK"
WRONG_PIECE = "This space does not contain your piece"
ONLY_2 = "You can only move a piece one space diagonally, or two when legally jumping"
PLAYER_1_UP = "Player 1 must move up"
PLAYER_2_DOWN = "Player 2 must move down"
SPACE_TAKEN = "The destination space is already taken"
JUMP_SELF = "You cannot jump your own piece"
JUMP_EMPTY = "You cannot jump an empty space"
UNKNOWN_INVALID = "Your move is not valid for an unknown reason"
#.................... 1 ........................................
def initializeBoard():
'''
Setup the board for a new game with 2 for player 2 pieces, 1 for player 1 pieces
and 0 for blank spaces.
returns a list with the players pieces setup for the start of a game
'''
# board = []
board = [[0 for i in range(8)] for j in range(8)]
for i in range(8):
if i ==0 or i == 2:
board[i] = [0, 2, 0, 2, 0, 2, 0, 2]
if i == 1:
board[i] = [2, 0, 2, 0, 2, 0, 2, 0]
if i == 5 or i == 7:
board[i] = [1, 0, 1, 0, 1, 0, 1, 0]
if i == 6:
board[i] = [0, 1, 0, 1, 0, 1, 0, 1]
for i in range(8):
print(board[i])
return board
#.................... 2 ........................................
def makeMove(player, move, board):
'''
Update the board with the requested move
move - the validated move
board - the game board
returns the updated board
'''
old_y = move[0]
old_x = move[1]
new_y = move[2]
new_x = move[3]
val1 = board[old_x][old_y]
val2 = board[new_x][new_y]
board[new_x][new_y] = val1
board[old_x][old_y] = val2
if debugMove: print("makeMove(", player, move, "board)")
return board

#.................... 3 ........................................
def validGameMove(player, move, board):
'''
Determine if the validated move request is a valid game move
move - a list of integers representing the moves in the order
[from column, from row, to column, to row]
player - the player number
board - the board currently in play
returns True if the move is valid else False
'''
old_y = move[0]
old_x = move[1]
new_y = move[2]
new_x = move[3]
val1 = board[old_x][old_y]
val2 = board[new_x][new_y]
print("player=",player,val1)
print("player=",player,val2)
if player==1:
if val1!=1:
return WRONG_PIECE
if val2==2:
return SPACE_TAKEN
if(new_x return PLAYER_1_UP
if(new_x>(old_x-2)):
return ONLY_2
if(new_x>(old_x-2)):
if((board[old_x-1][old_y])==1):
return JUMP_SELF
elif((board[old_x][old_y+1])==1):
return JUMP_SELF
elif((board[old_x-1][old_y])==0):
return JUMP_EMPTY
elif((board[old_x][old_y-1])==0):
return JUMP_EMPTY
else:
return OK_MOVE
elif player==2:
if val2!=2:
return...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here