#08-1###################################################
"""Write a program that asks the user to enter some text
and then counts how many articles are in the text.
Articles are the words 'a', 'an', and 'the'."""

##user_input =input("Enter Text: ") #love is a beautiful and profound an angelic being
##articles =["a","an","and"]
##words = user_input.split()
##count = 0
##for word in words:
##    if word in articles:
##        count +=1
##print("Total article =",count)


#08-2####################################################
""" Write a program that allows the user to enter five
numbers (read as strings). Create a string that consists
of the user’s numbers separated by plus signs. For
instance, if the user enters 2, 5, 11, 33, and 55, then
the string should be '2+5+11+33+55'."""

##user_input = input("Enter 5 numbers :") #1 2 3 4 5
##sepr = user_input.replace(" ", "+")
##print(sepr)


#08-3######################################################
"""(a) Ask the user to enter a sentence and print out the
third word of the sentence. (b) Ask the user to enter a
sentence and print out every third word of the sentence."""

##user_input = input("Enter a sentence: ")
###eg I love you ethan tirla and I promise to give you the best life has to offer
##sentence_words = user_input.split()
##print("a",sentence_words[2])
##for word in range(2,len(sentence_words),3):
##    print("b",sentence_words[word])
    

#08-4######################################################
"""

Write a program that asks the user to enter a sentence and
then randomly rearranges the words of the sentence.
Don’t worry about getting punctuation or capitalization
correct.

b) Do the above problem, but now make sure that the sentence
starts with a capital, that the original first word is not
capitalized if it comes in the middle of the sentence, and
that the period is in the right place.
"""

##from random import shuffle
##from string import punctuation
###user_sentence = input("Enter a sentence:  ")
##user_sentence = "I am a crypto billionaire ."
###eg I am a crypto billionaire .
###a
##L =user_sentence.split()
##shuffle(L)
##print(L)
###b
##punct =""
##sentence2=""
##if user_sentence[-1] in punctuation:
##    punct = user_sentence[-1]
##    sentence2 = user_sentence[0].lower() + user_sentence[1:-1]
###print(sentence2)
##l2= sentence2.split()
##shuffle(l2)
##sentence2 = ' '.join(l2) + punct
##sentence2 = sentence2[0].upper() + sentence2[1:]
##print(sentence2)
###b credit to https://github.com/Yaachaka/  for the solution of b


#08-5######################################################
"""Write a simple quote-of-the-day program.
The program should contain a list of quotes, and when the
user runs the program, a randomly selected quote should be
printed."""

##import random
##from random import randint
##Quotes_list = ["To double your income and success, triple \
##your investment in personal development and \
##professional mastery - Robin Sharma","Simplicity \
##is the soul efficiency - Austin Freeman", "A \
##journey of a thousand miles begins with a single \
##step -Lao Tzu","Everything happens for a reason. \
##It's okay if you don't know what that reason is yet \
##-Unknown"]
##len_list = len(Quotes_list)
##num =random.randint(0,len_list-1)
##print(Quotes_list[num])


#08-6######################################################
"""Write a simple lottery drawing program. The lottery
drawing should consist of six different numbers between 1
and 48."""

##import random
##from random import randint
##lottery_num = []
##while len(lottery_num) < 6:
##    random_num = random.randint(1,48)
##    lottery_num.append(random_num)
##print(lottery_num)


#08-7######################################################
"""
Write a program that estimates the average number of
drawings it takes before the user’s numbers are picked in a
lottery that consists of correctly picking six different
numbers that are between 1 and 10. To do this, run a loop
1000 times that randomly generates a set of user numbers and
simulates drawings until the user’s numbers are drawn. Find
the average number of drawings needed over the 1000 times
the loop runs.

"""

##from enum import Enum
##from random import sample
##class lottery(Enum):
##    LOTTERY_NUM = [i for i in range(1,11)]
##ITERATIONS = 1000
##def lottery_hand():
##    # Used sample function instead of calling the num of draws globally to practice with it.
##    L = sample(lottery.LOTTERY_NUM.value, 6)
##    return L
##def winning_hand(ITERATIONS):
##    count = 0
##    for i in range(ITERATIONS):
##        user_hand = lottery_hand()
##        comp_hand = lottery_hand()
##        if user_hand == comp_hand:
##            count += 1
##    return count    
##def main():
##    won = winning_hand(ITERATIONS)
##    print((won/ITERATIONS) * 100)
##if __name__ == '__main__':
##    main()


#08-9######################################################
"""
Write a simple quiz game that has a list of ten questions
and a list of answers to those questions. The game should
give the player four randomly selected questions to answer.
It should ask the questions one-by-one, and tell the player
whether they got the question right or wrong. At the end
it should print out how many out of four they got right.
"""

##from enum import Enum
##from random import choice
##class q_a(Enum):
##    QUES_ANS = {'Sky is blue: ':'T',
##                'Square has 3 sides: ':'F',
##                '100 pennies equal 1 USD dollar: ':'T',
##                'Leaves can change colors: ':'T',
##                'Coding sucks: ':'F'}
##N = 3 # Number of rounds.
##VALID_CHOICE = ['T', 'F']
##def quiz_game(N):
##    score = 0
##    for i in range(N):
##        current_ques_ans = get_ques_ans()
##        current_ques = unpack_ques(current_ques_ans)
##        current_ans = unpack_ans(current_ques_ans)
##        valid_user_input = validate_ans(current_ques, current_ans)
##        score = check_ans_score(current_ans, valid_user_input, score)
##    print(f'\nYour score is {score}.')
### Will return a tuple since choosing both items in the dictionary.        
##def get_ques_ans():
##    ques_ans = choice(list(q_a.QUES_ANS.value.items()))
##    return ques_ans
##def unpack_ques(current_ques_ans):
##    ques = current_ques_ans[0]
##    return ques
##def unpack_ans(current_ques_ans):
##    ans = current_ques_ans[1]
##    return ans
##def validate_ans(current_ques, current_ans):
##    valid = False
##    while not valid:
##        user_input = input(current_ques)
##        user_input = user_input.upper()
##        try:
##            if user_input in VALID_CHOICE:
##                valid = True
##            else:
##                print('\nYou did not indicate true or false. Please enter "T" or "F".')
##        except:
##            pass
##    return user_input
##def check_ans_score(current_ans, valid_user_input, score):
##    if current_ans == valid_user_input:
##        score += 1
##    else:
##        pass
##    return score    
##def main():
##    print('Welcome to True and False Quiz!')
##    print('')
##    print('Enter "T" if it is true or "F" if it is false.\n')
##    quiz_game(N)
##if __name__ == '__main__':
##    main()


#08-10######################################################
"""
Write a censoring program. Allow the user to enter some text
and your program should print out the text with all the curse
words starred out. The number of stars should match the length
of the curse word. For the purposes of this program, just use
the“curse” words darn, dang, freakin, heck, and shoot.
"""

##curseWordsList = ['darn', 'dang', 'freakin', 'heck', 'shoot']
##print('Welcome to the Censoring Progam.')
##print('The following are curse words that will be censored:\n',curseWordsList)
##message = input("Enter a message: ")
###message = message.lower()
##messageList = message.split()
##for i in range(len(messageList)):
##    if(messageList[i] in curseWordsList):
##        messageList[i] = "*" * len(messageList[i])
##print(*messageList)


#08-12######################################################
"""
Write a program that gets a string from the user containing
a potential telephone number. The program should print Valid
if it decides the phone number is a real phone number, and
Invalid otherwise. A phone number is considered valid as
long as it is written in the form abc-def-hijk or
1-abc-def-hijk. The dashes must be included, the phone
number should contain only numbers and dashes, and the
number of digits in each group must be correct.
"""

##def validate_input(message):
##    valid = False
##    while not valid:
##        user_input = input(message)
##        num = user_input.split('-')
##        try:
##            if (len(num[0]) == 1) and (len(num[1]) == 3) and (len(num[2]) == 3) and (len(num[3]) == 4):
##                valid = True
##            elif (len(num[0]) == 3) and (len(num[1]) == 3) and (len(num[2]) == 4):
##                valid = True
##            else:
##                print('Your format is off. Please enter a valid phone number.')
##        except IndexError:
##            print('A phone number was not inputted.')
##    return user_input
##def main():
##    print('Welcome to Phone Number Validation.\n')
##    print('The phone number format is 1-ABC-DEF-GHIJ or ABC-DEF-GHIJ.')
##    message = 'Enter a valid phone number: '
##    valid_num = validate_input(message)
##    print(f'\nThe number, {valid_num}, is valid.')
##if __name__ == '__main__':
##    main()
    

#08-13######################################################    
"""
Let L be a list of strings. Write list comprehensions that
create new lists from L for each of the following.
(a) A list that consists of the strings of s with their
first characters removed
(b) A list of the lengths of the strings of s
(c) A list that consists of only those strings of s that
are at least three characters long
"""

##L = ['apple', 'car', 'tree', 'I', 'watch', 'internet']
##print(L)
##M = [s[1:] for s in L]
##print(M)
##N = [len(s) for s in L]
##print(N)
##O = [s for s in L if len(s) >= 3]
##print(O)


#08-14###################################################### 
"""
Use a list comprehension to produce a list that consists of
all palindromic numbers between 100 and 1000.
"""

##L = [num for num in range(100, 1001)]
##M = []
##count = 0
##for i in L:
##    i = str(i)
##    if i == i[::-1]:
##        count+=1
##        M.append(int(i))
##print(f'\nThere are {count} numbers that are a palindromic.\n')
##print(M)

 
#08-17######################################################
"""
Write a program that finds the average of all of the entries
in a 4 × 4 list of integers.
"""


##import random
##from random import randint
##rows = 4
##cols = 4
##total = 0
##table = [[random.randint(0,3) for _ in range(cols)] for _ in range(rows)]
##print(table)
##for i in table:
##    for num in i:
##        total += num
##print("The total of all entries is", total)


  
#08-18######################################################  
"""
Write a program that creates a 10×10 list of random integers
between 1 and 100. Then do the following:
(a) Print the list.
(b) Find the largest value in the third row.
(c) Find the smallest value in the sixth column.
"""

##import random
##from random import randint
##rows = 10
##cols = 10
##total = 0
##table = [[random.randint(1,100) for _ in range(cols)] for _ in range(rows)]
##print(table)
##ctr = 0
##for i in table:
##    ctr += 1
##    if (ctr == 3):
##        print("The largest value in the third row is",max(i))
##    if (ctr == 6):
##        print("The smallest value in the sixth row is",min(i))
    

#08-19######################################################  
"""
Write a program that creates and prints an 8 × 8 list whose
entries alternate between 1 and 2 in a checkerboard pattern,
starting with 1 in the upper left corner.
"""

##import random
##from random import randint
##rows = 8
##cols = 8
##table = [[0 for _ in range(cols)] for _ in range(rows)]
##ctr = 0
##for i in table:
##    for j in range(8):
##        if (j%2 == 0):
##            i[j] = 1
##        else:
##            i[j] = 2
##print(table)    


#08-22######################################################
"""
The following is useful as part of a program to play
Battleship. Suppose you have a 5 × 5 list that consists of
zeroes and ones. Ask the user to enter a row and a column.
If the entry in the list at that row and column is a one,
the program should print Hit and otherwise it should print
Miss.
"""

##from random import randint
##from pprint import pprint
##MAP = [[randint(0,1) for column in range(5)] for row in range(5)]
##def validate_input(row_input, column_input, flag):
##    valid = False
##    while not valid:
##        try:
##            if flag == 0:
##                user_input = int(input(row_input))
##            else:
##                user_input = int(input(column_input))
##            if 0 <= user_input <= 4:
##                valid = True
##            else:
##                print('\nSorry you did not enter a number from the choices.')
##        except ValueError:
##            print('\nYou did not enter a number.')
##    return user_input
##def hit_miss(row, column):
##    if MAP[row][column] == 1:
##        print('Hit')
##    else:
##        print('Miss') 
##def main():
##    print('Welcome to Battleship.')
##    print('')
##    print('The board is 5x5 (25 choices total).')
##    print('You will first inout row and then column to indicate the point you want to target.')
##    print('The choices for the row and column will be 1 through 5.')
##    row_input = 'Enter 0, 1, 2, 3, or 4 for row: '
##    column_input = 'Enter 0, 1, 2, 3, or 4 for column: '
##    flag = 0
##    row = validate_input(row_input, column_input, flag)
##    flag = 1
##    column = validate_input(row_input, column_input, flag) 
##    hit_miss(row, column)
##    pprint(MAP)
##if __name__ == '__main__':
##    main()

  
#08-23######################################################
"""
This exercise is useful in creating a Memory game. Randomly
generate a 6 × 6 list of assorted characters such that there
are exactly two of each character. An example is shown below.

@ 5 # A A !
5 0 b @ $ z
$ N x ! N z
0 - + # b :
- : + c c x
"""


##from string import ascii_letters, punctuation, digits
##from random import sample, shuffle
##from pprint import pprint
##import numpy as np
### From string module, imported all corresponding characters and grouped them together in source variable.
##source = ascii_letters + punctuation + digits
### Using sample function from random module, grabbed 18 random characters from source string.
### After which, the random chars cloned to create pairs for memory game. 
### Note, sample returns a list.
##chars = sample(source, 18) * 2
### Used shuffle function to randomize the list of characters
##shuffle(chars)
### Used numpy instead of list comprehensions to create an array of the chars at a 6x6 size.
### After which, the array was converted to a list using the .tolist() method.
##L = np.array(chars).reshape(6,6).tolist()
##pprint(L)
  
  
