-
Notifications
You must be signed in to change notification settings - Fork 243
Blackjack
Sar Champagne Bielert edited this page Apr 8, 2024
·
7 revisions
Unit 1 Session 1 (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Will the input always be an integer?
- Yes.
- Should the function print anything out?
- Yes, print the results from inside the function.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Given a points total, print out the Blackjack game result.
1) Set up the function:
a) Create a new function with a parameter representing the score
b) Check each condition and print the appropriate result
2) Test the function for all possible results by:
a) Calling the function
def blackjack(score):
if score < 17:
print("Hit Me!")
elif score < 21:
print("Nice hand!")
elif score >= 21:
print("Bust!")
else:
print("Blackjack!")
blackjack(21) # Output: "Blackjack!"
blackjack(19) # Output: "Nice hand!"
blackjack(10) # Output: "Hit me!"
blackjack(25) # Output: "Bust!"