Assignment 04
Assignment 04
Programming Assignment 04
-
For loops
Instructions
The autograder will evaluate your code for a few testcases. If some testcases fail, the
autograder should show you what is your code output, and what is the expected output.
The autograder will give you a score based on the testcases, but a grader will manually
evaluate your coding style after the deadline. Style represents 30% of the coding assignment
grade.
Sample examples (the user input is in red, the printed output is in blue, and the prompt is in black):
How many words will you enter? > 4 How many words will you enter? > 3
Word #1 please > wow Word #1 please > hi
Word #2 please > oh Word #2 please > hi
Word #3 please > amazing Word #3 please > hi
Word #4 please > program Shortest: hi
Shortest: oh Longest: hi
Longest: program Average Length: 2.00
Average Length: 4.75
Exercise 2 - Blackjack
It is casino night in the Department of Computer Science and I am in charge of the Blackjack table.
You must write a program to help me do my job.
Blackjack is a card game played with one or several standard 52-card decks. The value of the
cards is calculated regardless of suits or colors. We will only use letters and digits to indicate the
different cards: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K. The object of the game is to reach 21 points or
to get as close to 21 points without going higher. The value of cards two through ten is their pip
value (2 through 10). Face cards (Jack, Queen, and King) are each worth ten. Aces can be worth
one or eleven , whichever is better for the player. A hand’s value is the sum of the card values.
Players are allowed to draw additional cards to improve their hands.
Each player has some cards in his hand. They must then make a decision of whether to Hit or
Stay. Hit means they request an additional card, Stay means they stop with their current total.
Players generally try to Hit until it is likely that another card will push them over 21. For example,
if a player has a 5 and a 7, there is a relatively low chance that another card would push them over
21 (only J, Q, and K would do so, since 12 + 10 = 22).On the other hand, if they have a 5, a 6,
and a 7, they will likely stay because any card above 3 will push them over 21 points.
• An Ace (A) should be counted as 11 if it puts the dealer between 17 and 21 points. If it puts
them over 21, though, it should be counted as 1.
Write a program (in the file exercise2.py) that does the following:
1. ask the user to enter his hand
2. then print out:
(a) ”Hit” if the dealer should take another card.
(b) ”Stay” if the dealer should not take another card.
(c) ”Bust” if the sum is already over 21.
Sample examples (the user input is in red, the printed output is in blue, and the prompt is in black):
Enter your hand: > A39 Enter your hand: > A397
Hit Stay
Enter your hand: > AA37K Enter your hand: > AAAA8
Bust Hit
Enter your hand: > 102Q Enter your hand: > AAA7
Bust Stay