Skip to content

Commit b69cf7d

Browse files
committed
Lab3FinalVersion
1 parent e3e37ca commit b69cf7d

File tree

2 files changed

+157
-97
lines changed

2 files changed

+157
-97
lines changed

code/daniel/03_NumberToPhrase/NumberToPhrase.py

Lines changed: 85 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,80 +18,14 @@
1818
# Convert a time given in hours and minutes to a phrase.
1919
#===================================================================================
2020

21-
from ast import NotIn
2221
import numbers
23-
from xml.dom import WrongDocumentErr
2422

25-
from cupshelpers import activateNewPrinter
2623

2724

2825
#====================================
2926
#Version1
3027
#====================================
3128

32-
onesNumberList = {
33-
0: "zero",
34-
1: "one",
35-
2: "two",
36-
3: "three",
37-
4: "four",
38-
5: "five",
39-
6: "six",
40-
7: "seven",
41-
8: "eight",
42-
9: "nine",
43-
}
44-
tensNumberList = {
45-
10: "ten",
46-
11: "eleven",
47-
12: "twelve",
48-
13: "thirteen",
49-
14: "fourteen",
50-
15: "fifteen",
51-
16: "sixteen",
52-
17: "seventeen",
53-
18: "eighteen",
54-
19: "ninteen",
55-
20: "twenty",
56-
30: "thirty",
57-
40: "fory",
58-
50: "fifty",
59-
60: "sixty",
60-
70: "seventy",
61-
80: "eighty",
62-
90: "ninty",
63-
}
64-
65-
66-
pickANumber = input("Pick a number between 0 and 99: ")
67-
intNum = int(pickANumber)
68-
tens_digit = intNum//10
69-
ones_digit = intNum%10
70-
# print(tens_digit)
71-
# print(ones_digit)
72-
73-
74-
while intNum > 99 or intNum < 0:
75-
print(f"Number is out of range")
76-
exit()
77-
78-
# print(onesNumberList.get(int(6)))
79-
while True:
80-
if intNum in onesNumberList:
81-
print(str(onesNumberList[intNum]))
82-
break
83-
elif intNum in tensNumberList:
84-
print(str(tensNumberList[intNum]))
85-
break
86-
elif intNum not in onesNumberList and intNum not in tensNumberList:
87-
# wordNum = tensNumberList[tens_digit*10] + onesNumberList[ones_digit*10]
88-
print(str(tensNumberList[tens_digit*10] + "-" + onesNumberList[ones_digit]))
89-
break
90-
91-
#=======================================
92-
#Version2
93-
#=======================================
94-
9529
# onesNumberList = {
9630
# 0: "zero",
9731
# 1: "one",
@@ -125,38 +59,16 @@
12559
# 90: "ninty",
12660
# }
12761

128-
# HundredNumberList = {
129-
# 100: "one hundred",
130-
# 200: "two hundred",
131-
# 300: "three hundred",
132-
# 400: "four hundred",
133-
# 500: "five hundred",
134-
# 600: "six hundred",
135-
# 700: "seven hundred",
136-
# 800: "eight hundred",
137-
# 900: "nine hundred",
138-
# }
13962

14063
# pickANumber = input("Pick a number between 0 and 99: ")
14164
# intNum = int(pickANumber)
142-
# wordNum = ""
143-
# hundred_digit = intNum//100
144-
145-
146-
# if intNum > 99:
147-
# tens_digit = (intNum//10)%10
148-
# else:
149-
# tens_digit = intNum//10
150-
65+
# tens_digit = intNum//10
15166
# ones_digit = intNum%10
152-
# actual_digit = (f"{tens_digit}{ones_digit}")
153-
# print(hundred_digit)
154-
# print(tens_digit)
155-
# print(ones_digit)
156-
# # print(f"{tens_digit}{ones_digit}")
157-
# # print(actual_digit)
67+
# # print(tens_digit)
68+
# # print(ones_digit)
69+
15870

159-
# while intNum > 1000 or intNum < 0:
71+
# while intNum > 99 or intNum < 0:
16072
# print(f"Number is out of range")
16173
# exit()
16274

@@ -168,10 +80,86 @@
16880
# elif intNum in tensNumberList:
16981
# print(str(tensNumberList[intNum]))
17082
# break
171-
# elif intNum not in onesNumberList and intNum not in tensNumberList and intNum < 99:
83+
# elif intNum not in onesNumberList and intNum not in tensNumberList:
17284
# # wordNum = tensNumberList[tens_digit*10] + onesNumberList[ones_digit*10]
17385
# print(str(tensNumberList[tens_digit*10] + "-" + onesNumberList[ones_digit]))
17486
# break
175-
# else:
176-
# print(str(HundredNumberList[hundred_digit*100] + (tensNumberList[tens_digit*10] + "-" + onesNumberList[ones_digit])))
177-
# break
87+
88+
#=======================================
89+
#Version2
90+
#=======================================
91+
92+
NumberList = {
93+
0: "zero",
94+
1: "one",
95+
2: "two",
96+
3: "three",
97+
4: "four",
98+
5: "five",
99+
6: "six",
100+
7: "seven",
101+
8: "eight",
102+
9: "nine",
103+
10: "ten",
104+
11: "eleven",
105+
12: "twelve",
106+
13: "thirteen",
107+
14: "fourteen",
108+
15: "fifteen",
109+
16: "sixteen",
110+
17: "seventeen",
111+
18: "eighteen",
112+
19: "ninteen",
113+
20: "twenty",
114+
30: "thirty",
115+
40: "fory",
116+
50: "fifty",
117+
60: "sixty",
118+
70: "seventy",
119+
80: "eighty",
120+
90: "ninty",
121+
100: "one hundred",
122+
200: "two hundred",
123+
300: "three hundred",
124+
400: "four hundred",
125+
500: "five hundred",
126+
600: "six hundred",
127+
700: "seven hundred",
128+
800: "eight hundred",
129+
900: "nine hundred",
130+
}
131+
132+
pickANumber = input("Pick a number between 0 and 99: ")
133+
intNum = int(pickANumber)
134+
#========
135+
#digits
136+
#========
137+
hundred_digit = intNum//100
138+
139+
if intNum > 99:
140+
tens_digit = intNum//10
141+
tens_digit_mod = tens_digit%10
142+
else:
143+
tens_digit = intNum//10
144+
145+
ones_digit = intNum%10
146+
#========
147+
print(hundred_digit)
148+
# print(tens_digit)
149+
print(tens_digit_mod)
150+
print(ones_digit)
151+
152+
153+
while intNum >= 1000 or intNum < 0:
154+
print(f"Number is out of range")
155+
exit()
156+
while True:
157+
if intNum in NumberList:
158+
print(str(NumberList[intNum]))
159+
break
160+
elif intNum not in NumberList and intNum < 99:
161+
print(str(NumberList[tens_digit*10] + "-" + NumberList[ones_digit]))
162+
break
163+
else:
164+
print(str(NumberList[hundred_digit*100] + " " + (NumberList[tens_digit_mod*10] + "-" + NumberList[ones_digit])))
165+
break
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Lab 4: Blackjack Advice
2+
3+
# Let's write a python program to give basic blackjack playing advice during a game by asking the player for cards.
4+
# First, ask the user for three playing cards (A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, or K).
5+
# Then, figure out the point value of each card individually. Number cards are worth their number, all face cards are worth 10.
6+
# At this point, assume aces are worth 1. Use the following rules to determine the advice:
7+
8+
# Less than 17, advise to "Hit"
9+
# Greater than or equal to 17, but less than 21, advise to "Stay"
10+
# Exactly 21, advise "Blackjack!"
11+
# Over 21, advise "Already Busted"
12+
13+
# Print out the current total point value and the advice.
14+
15+
# What's your first card? Q
16+
# What's your second card? 2
17+
# What's your third card? 3
18+
# 15 Hit
19+
20+
# What's your first card? K
21+
# What's your second card? 5
22+
# What's your third card? 5
23+
# 20 Stay
24+
25+
# What's your first card? Q
26+
# What's your second card? J
27+
# What's your third card? A
28+
# 21 Blackjack!
29+
#=============================================================
30+
31+
import random
32+
33+
Facecards = {
34+
"K": 10,
35+
"Q": 10,
36+
"J": 10,
37+
"10": 10,
38+
"9": 9,
39+
"8": 8,
40+
"7": 7,
41+
"6": 6,
42+
"5": 5,
43+
"4": 4,
44+
"3": 3,
45+
"2": 2,
46+
"A": 1
47+
}
48+
49+
Question1 = input("What's your first card?: ")
50+
Question2 = input("What's your second card?: ")
51+
Question3 = input("What's your third card?: ")
52+
53+
total = int(Question1) + int(Question2) + int(Question3)
54+
55+
56+
57+
if total < 17:
58+
print("Hit")
59+
elif total <= 17 and total < 21:
60+
print("Stay")
61+
elif total == 21:
62+
print("BlackJack!")
63+
else:
64+
print("Busted")
65+
66+
67+
68+
# Version 2 (optional)
69+
70+
# Aces can be worth 11 if they won't put the total point value of both cards over 21. Remember that you can have multiple aces in a hand.
71+
# Try generating a list of all possible hand values by doubling the number of values in the output whenever you encounter an ace.
72+
# For one half, add 1, for the other, add 11. This ensures if you have multiple aces that you account for the full range of possible values.

0 commit comments

Comments
 (0)