ACIT 1515辅导、讲解Python编程语言、辅导D2L留学生、讲解Python设计
调试Matlab程序|调试Matlab程序
ACIT 1515 Midterm Exam
This exam has three questions. Marks will be assigned for each question by testing with the instructors test data.
Part marks are awarded.
Marks will be deducted for:
incorrect output and/or return values: function does not meet specification
incorrect or unnecessarily complex function design strategies (your algorithm)
inappropriate use of data structures and variables
inappropriate length and/or use of functions
poor commenting, variable names, and program layout
code that is clearly cut/paste from internet, where the code does not reflect techniques learned in class or techniques that can’t be easily explained by the student
Question 1: Bug Fixing
/ 6
Question 2: Code Completion
/ 16
Question 3: Program Creation
/ 20
Save and upload a single file for each of the questions, named as specified.
Save your programs as you finish them, as you will be required to upload your final copies to D2L at the end of the exam. It is your responsibility to keep track of your files, and to upload the correct versions. Only the last version of each copy will be checked.
Rules:
1.Turn off your phone. Yes, off
2.Place your phone on your desk in front of you, where the instructor can see it.
3.No phones, no talking, no getting help from anyone else – which means no email, text, chat etc..
4.You CAN use your textbook, previous assignments, and code.
5.You CAN use any websites as long as you do not post a question anywhere or otherwise communicate anyone.
6.The test is timed: 2 hours max – at this point the D2L dropbox is closed
Question 1: Bug Fixing
Using the following source code to create a file named reverse.py. Repair the errors that it generates so it is able to match the Example Usage below when run.
Filename
reverse.py
Source Code
#! /usr/bin/env python3
def reverse(phrase):
num_letters = len(phrase)
letter_count = 0
while letter_count < num_letters:
reversed_phrase += phrase[num_letters - letter_count]
letter_count += 1
return reversed_phrase
def main():
phrases = []
phrases.append("Exams are not the most authentic of assessments")
phrases.append("Loops need to end")
phrases.append("Exams are not the most authentic of assessments")
for phrase in phrases:
print(reverse(phrase))
if __name__ == '__main__':
main()
Example Usage
PS>.\reverse.py
stnemssessa fo citnehtua tsom eht ton era smax
dne ot deen spoo
stnemssessa fo citnehtua tsom eht ton era smax
Question 2: Code Completion
Using the source code below as a starting point create a file shuffle.py that meets the requirements outlined in the comments of source code and the matches the outputs in the Example Usage.
FILENAME
shuffle.py
Source Code
'''
This module builds a deck of cards, shuffles them, and deals out a list of hands
of a specified number of cards for the specified number of players
'''
import pprint
import random
suits = ['Hearts', 'Diamonds', 'Spades', 'Clubs']
card_names = {
2: 2,
3: 3,
4: 4,
5: 5,
6: 6,
7: 7,
8: 8,
9: 9,
10: 10,
11: 'Jack',
12: 'Queen',
13: 'King',
14: 'Ace'
}
def make_suit(suit):
'''
Generates a list containing all of the cards in a single suit
Use the card_names dictionary to generate each card "name" based
on its "value" from 2 to 14 combined with its suit.
For example a card with value of 11 would have a name of 'Jack'
Args:
suit (str): the suit for which to generate the cards one of:
Hearts, Diamonds, Spades, or Clubs.
Returns:
List[str]: a list containing all the cards in the suit.
each card is a string with the card value
followed by the suit in the format:
of
Examples:
4 of Hearts
8 of Diamonds
10 of Clubs
Queen of Hearts
Ace of Spades
'''
suit_cards = []
# your code goes here
return suit_cards
def make_deck():
'''
Generates a list containing a string for each of the cards in a standard
playing deck
A "standard" deck of playing cards consists of 52 Cards in each of the 4
suits of Spades, Hearts, Diamonds, and Clubs. Each suit contains 13 cards:
2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace
The deck is created by creating the cards for each suit in a loop.
Returns:
List[str]: List containing a string for each of the cards in a standard
deck. See make_suit() for string format
'''
deck = []
# your code goes here
return deck
def shuffle_deck(deck):
'''
Shuffles deck of cards in place, i.e. modifies the passed deck parameter
but doesn't return a new value
Args:
deck (List[str]): List containing strings, each representing cards in a
standard deck
'''
random.shuffle(deck)
def deal(num_of_players, cards_per_player, deck):
'''
Creates a nested list of hands for the requested number of players.
Each hand is a list holding the requested number of cards.