Please use Python 3.6 I need the answer for question 16.10 it says to use listin
ID: 3827025 • Letter: P
Question
Please use Python 3.6 I need the answer for question 16.10 it says to use listings 16.4 - 16.6 which is why I included them in the bottom..
16.10* (Execution time for prime numbers) Write a program that obtains the execution time for finding all the prime numbers less than 8,000,000, 10,000,000, 12,000,000, 14,000,000, 16,000,000, and 18,000,000 using the algorithms in Listings 16.4-16. 6. Your program should print a table like this 10000000 12000000 14000000 16000000 18000000 8000000 Listing 16.4 Listing 16.5 Listing 16.6 The programs you are doing this week will take a LONG time to run even on fast computers. To speed your development time I suggest you limit the size of the problem until you are ready to actually test the time your program takes to find the required values. For example, problem 16.10 says to test for values of 8,000,000 through 18,000,000. During the development of your program use values of 8,000 to 18,000. Only after you are satisfied that your program work correctly, you can change to the actual test values (then go out for dinner!). ere are the algorithims: 16.4 Pattern matching) Write a program that prompts the user to enter two strings and tests whether the second string is a substring in the first string (Don't use the find method in the str class.) Analyze the time complexity of your algorithm. Here is a sample run of the program:Explanation / Answer
Q1. Here, we are calculating time taken in calculating primes less than 8000.
import time
startTime = time.time()
startRange = 0
endRange = 8000000
print("Prime numbers between",startRange,"and",endRange,"are:")
for number in range(startRange,endRange + 1):
if number > 1:
for i in range(2,number):
if (number % i) == 0:
break
else:
print(number) #Only if you want to print
endTime = time.time()
print("Time taken to find primes less than 8000000 ",endTime - startTime)
You do this for each of the values you want to by changing the endRange, and the time taken is displayed.
Q2.
def checkSubString(myString1, myString2, m, n):
if m == 0: return True #If length is 0
if n == 0: return False
if myString1[m-1] == myString2[n-1]:
return checkSubString(myString1, myString2, m-1, n-1)
return checkSubString(myString1, myString2, m, n-1)
myString1 = raw_input("Enter first String") #User Input
myString2 = raw_input("Enter second String")
m = len(myString1)
n = len(myString2)
if checkSubString(myString1, myString2, m, n):
print "Yes"
else:
print "No"