Skip to content

Commit b5c69c1

Browse files
committed
Merge branch 'main' into daniel-lab04-blackjackAdvice
try fix
2 parents 80e7fc9 + 33e5b33 commit b5c69c1

File tree

6 files changed

+339
-2
lines changed

6 files changed

+339
-2
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Ignore any user's VSCode workspace file
1+
# Ignore any user's VSCode workspace file and vscode local settings
22
*code-workspace
3-
.VSCode
3+
.vscode
44

55
# Created by https://www.toptal.com/developers/gitignore/api/python,windows,macos
66
# Edit at https://www.toptal.com/developers/gitignore?templates=python,windows,macos
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#version 1
2+
3+
low_numbers = {
4+
0: "zero",
5+
1: "one",
6+
2: "two",
7+
3: "three",
8+
4: "four",
9+
5: "five",
10+
6: "six",
11+
7: "seven",
12+
8: "eight",
13+
9: 'nine',
14+
10: 'ten',
15+
11: 'eleven',
16+
12: 'tweleve',
17+
13: 'thirty',
18+
14: 'fourteen',
19+
15: 'fifteen',
20+
16: 'sixteen',
21+
17: 'seventeen',
22+
18: 'eighteen',
23+
19: 'nineteen'
24+
25+
}
26+
27+
ten = {
28+
2: "twenty",
29+
3: "thirty",
30+
4: "forty",
31+
5: "fifty",
32+
6: "sixty",
33+
7: "seventy",
34+
8: "eighty",
35+
9: "nintey"
36+
}
37+
# # print(low_numbers[3])
38+
enter = input('Please enter a number between 0 - 99 : ')
39+
40+
number = int(enter)
41+
42+
def convert_number(number):
43+
# return number]
44+
if number < 20:
45+
return low_numbers[number]
46+
elif number < 100:
47+
tens_digit = number//10
48+
ones_digit = number%10
49+
last_one = int(str(number)[-1:]) #calling the the last number that is being inputed
50+
if last_one == 0: # its saying that its only calling the last number if it is 0
51+
return f'{ten[tens_digit]}' # once all those requirments are met it'll return the tens but what its doing is that it goes into the tens and then calling out the 10s digit it looks at the tens position of what was inputed and reads of the single digit
52+
53+
54+
return f"{ten[tens_digit]} - {low_numbers[ones_digit]}"
55+
56+
57+
print(convert_number(number))
58+
59+
60+
61+
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#version 2
2+
3+
4+
5+
from requests import request
6+
7+
8+
low_numbers = {
9+
0: "zero",
10+
1: "one",
11+
2: "two",
12+
3: "three",
13+
4: "four",
14+
5: "five",
15+
6: "six",
16+
7: "seven",
17+
8: "eight",
18+
9: 'nine',
19+
10: 'ten',
20+
11: 'eleven',
21+
12: 'tweleve',
22+
13: 'thirteen',
23+
14: 'fourteen',
24+
15: 'fifteen',
25+
16: 'sixteen',
26+
17: 'seventeen',
27+
18: 'eighteen',
28+
19: 'nineteen'
29+
30+
}
31+
32+
ten = {
33+
2: "twenty",
34+
3: "thirty",
35+
4: "forty",
36+
5: "fifty",
37+
6: "sixty",
38+
7: "seventy",
39+
8: "eighty",
40+
9: "nintey"
41+
}
42+
43+
hundreds = {
44+
1: "one hundred",
45+
2: "two hundred",
46+
3: "three hundred",
47+
4:'four hundred',
48+
5:'five hundred',
49+
6:'six hundred',
50+
7:'seven hundred',
51+
8:'eight hundred',
52+
9:'nine hundred'
53+
54+
}
55+
# print(low_numbers[3])
56+
enter = input('Please enter a number between 0 - 999 : ')
57+
58+
number = int(enter)
59+
60+
def convert_number(number):
61+
# return number]
62+
if number < 20:
63+
return low_numbers[number]
64+
65+
# elif number < 100:
66+
67+
# tens_digit = number // 10
68+
# # print('10s digit: ', tens_digit)
69+
# ones_digit = number % 10 #takes whatever number and divides that by 10 and then gives the remainder
70+
# # print('1s digit: ', ones_digit)
71+
# # return f"{ten[tens_digit]} - {low_numbers[ones_digit]}"
72+
# tens_word = ten[tens_digit]
73+
# ones_word = low_numbers[ones_digit]
74+
# # print('ones word: ', ones_word)
75+
# # print('type of ones word: ', type(ones_word))
76+
77+
# # print(ones_word[0])
78+
# # print(ones_word[1])
79+
# # print(ones_word[2])
80+
# # print(ones_word[3])
81+
82+
# return f'{tens_word + " " + low_numbers[ones_digit]}'
83+
84+
elif number < 100:
85+
tens_digit = number//10
86+
ones_digit = number%10
87+
last_one = int(str(number)[-1:]) #calling the the last number that is being inputed
88+
if last_one == 0: # its saying that its only calling the last number if it is 0
89+
return f'{ten[tens_digit]}'
90+
91+
elif number <= 999:
92+
hundreds_digit = number // 100 #floor divide regular division with no remainder
93+
hundreds_word = hundreds[hundreds_digit]
94+
last_two = int(str(number)[-2:]) #python get last two digits in number stack exchange
95+
last_one = int(str(number)[-1:])
96+
if last_two == 0:
97+
return f'{hundreds_word}'
98+
99+
100+
101+
if last_two <=19: #catching all the numbers below 20
102+
return f'{hundreds_word + " " +low_numbers[last_two] }'
103+
104+
tens_digit = number // 10
105+
new_tens = tens_digit % 10
106+
ones_digit = number % 10
107+
tens_word = ten[new_tens]
108+
ones_word = low_numbers[ones_digit]
109+
if last_one == 0:
110+
return f'{hundreds_word + " " + ten[new_tens]}' #placing this here to be able to get the numbers with 0 at the end, from having it say number then adding zero also placement beacause it needs to run all of that to be able to distinguish when it needs to use it
111+
112+
return f'{hundreds_word + " " + tens_word + " " + ones_word}'
113+
114+
115+
# return hundreds_digit, tens_digit
116+
# return f"{hundreds_word} - {ten[tens_digit]} - {low_numbers[ones_digit]}"
117+
118+
print(convert_number(number))
119+
120+
# print(convert_number(111))
121+
# print(convert_number(813))
122+
# print(convert_number(140))

code/jonpan/lab07.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#Lab07 Credit Card Validator
2+
3+
def credit_card_validator(credit_card_number):
4+
5+
#Convert the input string into a list of ints
6+
7+
cc_to_list = list(credit_card_number)
8+
9+
for i in range(len(cc_to_list)):
10+
cc_to_list[i] = int(cc_to_list[i])
11+
12+
print(cc_to_list)
13+
14+
# Slice off the last digit. That is the check digit.
15+
16+
check_digit = cc_to_list.pop(-1)
17+
# print(check_digit)
18+
19+
# Reverse the digits.
20+
21+
reversed_list = cc_to_list[::-1]
22+
print(reversed_list)
23+
24+
# Double every other element in the reversed list (starting with the first number in the list).
25+
26+
# for i in range(0, len(reversed_list), 2):
27+
# reversed_list[i] = int(reversed_list[i]) * 2
28+
# print(reversed_list[i])
29+
30+
double_list = []
31+
32+
for i in range(len(reversed_list)):
33+
if i % 2 == 0:
34+
double_list.append(reversed_list[i] * 2)
35+
else:
36+
double_list.append(reversed_list[i])
37+
38+
print(double_list)
39+
40+
# Subtract nine from numbers over nine.
41+
42+
subtract_list = []
43+
44+
for i in range(len(double_list)):
45+
46+
if (double_list[i]) > 9:
47+
subtract_list.append(double_list[i] - 9)
48+
else:
49+
subtract_list.append(double_list[i])
50+
51+
print(subtract_list)
52+
53+
# Sum all values.
54+
55+
sumall = str(sum(subtract_list))
56+
57+
print(sumall)
58+
59+
# Take the second digit of that sum.
60+
61+
second_digit = sumall[1]
62+
63+
print(second_digit)
64+
65+
# If that matches the check digit, the whole card number is valid.
66+
67+
if second_digit == str(check_digit):
68+
print("Valid!")
69+
70+
print(credit_card_validator("4556737586899855"))
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
def credit_card_input():
2+
"""Takes credit card number as user input and returns as a string."""
3+
user_input = input("Enter a valid 16 digit credit card number: ")
4+
5+
return user_input
6+
7+
def credit_card_input_validation(user_input):
8+
""""Takes the output from credit_card_input() and first checks if the input was 16 characters. Then converts number as string to a list of ints."""
9+
10+
if len(user_input) != 16:
11+
print(f'{user_input} is not a valid card number. Please validate your card number and try again.')
12+
main()
13+
else:
14+
card_as_list = []
15+
16+
for char in user_input:
17+
card_as_list.append(int(char))
18+
19+
return card_as_list
20+
21+
def reverse_list(card_as_list):
22+
"""Takes the output from credit_card_input_validation() and reverses the list of ints."""
23+
reversed_list = []
24+
index = -1
25+
26+
for num in card_as_list:
27+
reversed_list.append(card_as_list[index])
28+
index -= 1
29+
30+
return reversed_list
31+
32+
def double_every_other_number(reversed_list):
33+
"""Takes a list of ints and doubles every other number."""
34+
index = 0
35+
doubled_list = reversed_list
36+
37+
while index < len(doubled_list):
38+
doubled_list[index] *= 2
39+
index += 2
40+
41+
return doubled_list
42+
43+
def subtract_nine(doubled_list):
44+
"""If number is greater than nine, subtract nine."""
45+
nine_diff_list = doubled_list
46+
index = 0
47+
48+
while index < len(nine_diff_list):
49+
if nine_diff_list[index] > 9:
50+
nine_diff_list[index] -= 9
51+
index += 1
52+
else:
53+
index +=1
54+
55+
return nine_diff_list
56+
57+
def validate_check_digits(check_digit1, check_digit2):
58+
"""If the two inputs equal, returns Valid or Invalid"""
59+
if check_digit1 == check_digit2:
60+
return "Card Valid"
61+
else:
62+
return "Card Invalid"
63+
64+
def main():
65+
"""Main function to validate credit card numbers."""
66+
user_input = credit_card_input()
67+
68+
card_as_list = credit_card_input_validation(user_input)
69+
70+
check_digit1 = card_as_list.pop()
71+
72+
reversed_list = reverse_list(card_as_list)
73+
74+
doubled_list = double_every_other_number(reversed_list)
75+
76+
nine_diff_list = subtract_nine(doubled_list)
77+
78+
check_digit2 = int(str(sum(nine_diff_list))[-1])
79+
80+
test_var = validate_check_digits(check_digit1, check_digit2)
81+
print(test_var)
82+
83+
main()

get_greeting.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Good evening kathy

0 commit comments

Comments
 (0)