#07-1###################################################
# Write a program that asks the user to enter a list of
# integers. Do the following:
# (a) Print the total number of items in the list.
# (b) Print the last item in the list.
# (c) Print the list in reverse order.
# (d) Print Yes if the list contains a 5 and No otherwise.
# (e) Print the number of fives in the list.
# (f) Remove the first and last items from the list, sort
#     the remaining items, and print the result.

##fiveCtr = 0
##numString = input("Enter a list of numbers separated by blanks: ")
##numList = numString.split()
##print("The total numbers in the list:",len(numList))
##print("The last item in the list" ,numList[-1])
##print("The list reversed:",numList[::-1])
##for i in range(len(numList)):
##   if int(numList[i]) == 5:
##      fiveCtr += 1
##if (fiveCtr > 0):
##    print("Yes, the list contains a five")
##else:
##    print("No, there are no fives in the list")
##print("The number of fives in the list:", fiveCtr)
##numList.pop(0)
##numList.pop(-1)
##print("The list after removing the first and last items:",numList)
##numList.sort()
##print("The remaining list sorted:",numList)


#07-2####################################################
# Write a program that generates a list of 20 random
# numbers between 1 and 100.
# (a) Print the list.
# (b) Print the average of the elements in the list.
# (c) Print the largest and smallest values in the list.
# (d) Print the second largest and second smallest entries
#     in the list
# (e) Print how many even numbers are in the list.


##import random
##from random import randint
##numList =[]
##ctr = 0
##total = 0
##evenCtr = 0
##for i in range(20):
##    numList.append(randint(1,100))
##    total += numList[i]
##average = total/20
##print(numList)
##print("Average of list",average)
##numList.sort()
##print("Largest number:",numList[-1])
##print("Second largest number:",numList[-2])
##print("Smallest number:",numList[0])
##print("Second smallest number:",numList[1])
##for i in numList:
##    if i%2==0:
##        evenCtr += 1
##print("Number of even numbers in the list:",evenCtr)



#07-3######################################################
# Start with the list [8,9,10]. Do the following:
# (a) Set the second entry (index 1) to 17   [8,17,10]
# (b) Add 4, 5, and 6 to the end of the list [8,17,10,4,5,6]
# (c) Remove the first entry from the list   [17,10,4,5,6]
# (d) Sort the list                          [4,5,6,10,17]
# (e) Double the list  [4,5,6,10,17,4,5,6,9,10,17]
# (f) Insert 25 at index 3    [4,5,6,25,10,17,4,5,6,10,17]
# The final list should equal [4,5,6,25,10,17,4,5,6,10,17]


##numList =[8,9,10]
##numList[1]=17
##numList.append(4)
##numList.append(5)
##numList.append(6)
##numList.pop(0)
##numList.sort()
##ls =[]
##for i in numList:
##    ls.append(i)
##numList.extend(ls)
##numList.insert(3,25)
##print(numList)


#07-4######################################################
# Ask the user to enter a list containing numbers between
# 1 and 12. Then replace all of the entries in the list
# that are greater than 10 with 10.

##input_num = eval(input("Enter a list of numbers between 1 and 12: "))
##number_list =[]
##number_list.extend(input_num)
##print(number_list)
##for i in range(len(number_list)):
##    if number_list[i] > 10:
##        number_list[i] = 10
##print(number_list)

#07-5######################################################
# Ask the user to enter a list of strings. Create a new
# list that consists of those strings with their
# first characters removed.


##input_string = input("Enter a list of strings: ").split(",")
##stringList = []
##stringList.extend(input_string)
##print(stringList)
##for i in range(len(stringList)):
##    stringList[i]=stringList[i][1:]
##print(stringList)


#07-6######################################################
# Create the following lists using a for loop.
# (a) A list consisting of the integers 0 through 49
# (b) A list containing the squares of the integers 1 through 50.
# (c) The list ['a','bb','ccc','dddd', . . . ] that ends with 26
# copies of the letter z.

##import random
##import math
##number_list = []
##square_list =[]
##list1 =[]
##for i in range(0,50):
##    number_list.append(i)
##print(number_list)
##for i in range(1,51):
##    square_list.append(i*i)
##print(square_list)
##
##alphabet=['a','b','c','d','e','f','g','h','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
###alphabet = ["a","b","c","d"]
##for i in range(len(alphabet)):
##     list1.append(alphabet[i]*(i+1))
##print(list1)


# #07-7######################################################
# Write a program that takes any two lists L and M of the
# same size and adds their elements together to form a new
# list N whose elements are sums of the corresponding elements
# in L and M. For instance, if L=[3,1,4] and M=[1,5,9], then N
# should equal [4,6,13].


##L =[3,1,4]
##M =[1,5,9]
##N =[]
##for i in range(len(L)):
##    N.append(L[i] + M[i])
##print(N)


#07-8######################################################
# Write a program that asks the user for an integer and
# creates a list that consists of the factors of that integer.


##input_int=eval(input("Enter Interger: "))
##number_list=[]
##for i in range(1,input_int+1):
##    if input_int%i == 0:
##        number_list.append(i)
##print(number_list)



#07-9######################################################
# When playing games where you have to roll two dice, it is
# nice to know the odds of each # roll. For instance, the
# odds of rolling a 12 are about 3%, and the odds of
# rolling a 7 are about 17%. You can compute these
# mathematically, but if you don’t know the math, you can
# write a program to do it. To do this, your program should
# simulate rolling two dice about 10,000 times and compute
# and print out the percentage of rolls that come out to be
# 2, 3, 4, . . . , 12.


##from random import randint
##dice_roll=[]
##outcome ={2:0,3:0,4:0,5:0,6:0,7:0,8:0,9:0,10:0,11:0,12:0}
##sim =10000
##for simulations in range(sim):
##    first_dice_roll = randint(1,6)
##    second_dice_roll = randint(1,6)
##    sum_dice =(first_dice_roll + second_dice_roll)
##    # print(sum_dice)
##    outcome[sum_dice] += 1
##for key in outcome.keys():
##    # print("Percentage for rolling a sum of %s is:"%(key,outcome[key]/sim*100))
##    print("Percentage for rolling a sum of %s is: %s" % (key, outcome[key] / sim * 100))


#07-10######################################################
# Write a program that rotates the elements of a list so
# that the element at the first index moves to the second
# index, the element in the second index moves to the third
# index, etc., and the element in the last index moves to
# the first index.

##listOriginal = [1,2,3,4]
##listRotated = [""]
##listRotated[0] = listOriginal[len(listOriginal)-1]
##holdNext = ""
##for i in range(len(listOriginal)-1):
##    listRotated.append(listOriginal[i])
##    holdNext = listOriginal[i+1]
###list2.insert(0,holdLast)   
##print("Original list:",listOriginal,"\nRotated list:",listRotated)



#07-11######################################################
# Using a for loop, create the list below, which consists of
# ones separated by increasingly many zeroes. The last two
# ones in the list should be separated by ten zeroes.
# [1,1,0,1,0,0,1,0,0,0,1,0,0,0,0,1,....]


### Initialising for the sequence start
##num_list =[1]
##for i in range(11):
##    num_list = num_list + (i * [0]) + [1]
##print(num_list)


#07-12######################################################
# Write a program that generates 100 random integers that
# are either 0 or 1. Then find the longest run of zeros, the
# largest number of zeros in a row. For instance, the
# longest run of zeros in [1,0,1,1,0,0,0,0,1,0,0] is 4.

##import random
##random_list = []
##c=0
##max_count=0
##for i in range(100):
##   n = random.randint(0,1)
##   random_list.append(n)
##print(random_list)
##for j in random_list:
##    c = c+1 if j == 0 else 0
##    max_count = max(max_count,c)
##print("The longest run of zeros is",max_count)


#07-13######################################################    
# Write a program that removes any repeated items from a list
# so that each item appears at most once. For instance, the
# list [1,1,2,3,4,3,0,0] would become [1,2,3,4,0].


##ls = [1,1,2,2,3,4,3,0,0]
##a = []
##for i in ls:
##    if i  not in a:
##        a.append(i)        
##print(a)



#07-14######################################################    
"""
Write a program that asks the user to enter a length in feet.
The program should then give the user the option to convert
from feet into inches, yards, miles, millimeters, centimeters,
meters, or kilometers. Say if the user enters a 1, then the
program converts to inches, if they enter a 2, then the
program converts to yards, etc. While this can be done with
if statements, it is much shorter with lists and it is also
easier to add new conversions if you use lists.
"""


formulaList = [12,1/3,1/5280,304.8,30.48,0.3048,0.0003048]
typesList = ["inches","yards","miles","millimeters","centimeters","meters","kilometers"]
feet = eval(input("Enter a length in feet: "))
i = eval(input("Enter an index: "))
print(feet,"feet =", formulaList[i]*feet,typesList[i])



#07-15######################################################
"""
There is a provably unbreakable cipher called a one-time pad.
The way it works is you shift each character of the message
by a random amount between 1 and 26 characters, wrapping
around the alphabet if necessary. For instance, if the
current character is y and the shift is 5, then the new
character is d. Each character gets its own shift, so there
needs to be as many random shifts as there are characters in
the message. As an example, suppose the user enters secret.
The program should generate a random shift between 1 and 26
for each character. Suppose the randomly generated shifts are
1, 3, 2, 10, 8, and 2. The encrypted message would be thebmv.
(a) Write a program that asks the user for a message and
encrypts the message using the one-time pad. First convert the
string to lowercase. Any spaces and punctuation in the string
should be left unchanged. For example, Secret!!! becomes
thebmv!!! using the shifts above.
(b) Write a program to decrypt a string encrypted as above.
The reason it is called a one-time-pad is that the list of
random shifts should only be used once. It becomes easily
breakable if the same random shifts are used for more than
one message. Moreover, it is only provably unbreakable if the
random numbers are truly random, and the numbers generated by
randint are not truly random. For this problem, just use
randint, but for cryptographically safe random numbers, see
Section 22.8.
"""

# TO DO
    
