ENGR-131 Name : _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Spring 2020 first last Your Magic Number is where is the number of letters in your first name and is the number of letters in your...

1 answer below »
Final Assignment, need help with!


ENGR-131Name : _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Spring 2020 first last Your Magic Number is where is the number of letters in your first name and is the number of letters in your second name. Record it here before you start. M = _ _ _ _ Instructions: Complete each of the five questions. Work must be your own. No collaboration allowed. Due Date: PDF must be uploaded by Tuesday June9 before 11:59PM 1. Numerical Exploration: Primes, Semiprimes and Palindromes Here are two free methods to use in your solution. import math def is_prime(n): if n<2: return="" 0="" for="" d="" in="" range(2,="" round(math.sqrt(n))="" +="" 1):="" if="" not="" n="" %="" d:="" return="" 0="" return="" 1="" def="" is_palindrome(n):="" if="" n="">< 0:="" return="" 0="" #="" don’t="" check="" negative="" numbers="" forward_string="str(n)" backward_string="forward_string[::-1]" return="" forward_string="=" backward_string="" a.="" generate="" a="" sorted="" list="" p1="" of="" all="" the="" primes="" up="" to="" m,="" your="" magic="" number.="" p1="[2," 3,="" 5,="" …]="" how="" many="" primes="" are="" in="" your="" list="" p1?="" ans:="" _="" _="" _="" b.="" a="" semiprime="" (or="" biprime)="" is="" a="" positive="" integer="" n="" than="" can="" be="" written="" as="" the="" product="" of="" two="" primes,="" so="" where="" and="" are="" both="" primes.="" the="" two="" primes="" can="" be="" the="" same,="" so="" the="" first="" semiprime="" is="" 4.="" using="" a="" set="" comprehension="" generate="" all="" the="" semiprimes="" p2="" less="" than="" or="" equal="" to="" m.="" tip:="" easiest="" with="" two="" for="" loops="" and="" one="" filter="" (if="" statement)="" in="" your="" initial="" set="" comprehension.="" then="" convert="" the="" set="" to="" a="" list="" using="" list()="" and="" sort="" it.="" how="" many="" semiprimes="" are="" in="" your="" list="" p2?="" ans:="" _="" _="" _="" c.="" hypothesis:="" every="" positive="" integer="" n="" is="" the="" sum="" of="" a="" prime="" and="" a="" semiprime,="" so="" we="" can="" write="" where="" ,="" and="" are="" all="" primes.="" this="" can't="" quite="" be="" true="" since="" the="" smallest="" prime="" is="" 2="" and="" the="" smallest="" semiprime="" is="" 4,="" so="" we="" must="" exclude="" all="" numbers="" less="" than="" 6.="" list="" any="" additional="" numbers="" that="" cannot="" be="" represented="" in="" this="" form="" checking="" all="" the="" way="" up="" to="" m.="" the="" exceptions="" are:="" 1,="" 2,="" 3,="" 4,="" 5="" and="" _="" _="" _="" _="" _="" _="" _="" _="" d.="" find="" all="" the="" three-digit,="" palindromic="" semiprimes.="" how="" many="" are="" there?="" _="" _="" _="" _="" _="" e.="" find="" all="" the="" four-digit,="" palindromic="" semiprimes.="" how="" many="" are="" there?="" _="" _="" _="" _="" _="" 2.="" files="" and="" searching="" files="" download="" the="" text="" file="" named="" baskervilles.txt="" which="" contains="" the="" complete="" test="" for="" arthur="" conan="" doyle's="" "the="" hound="" of="" the="" baskervilles".="" file="" was="" obtained="" from="" project="" gutenberg.="" a.="" we="" are="" going="" to="" study="" the="" words="" in="" this="" document.="" but="" first,="" complete="" this="" method="" which="" given="" a="" word,="" converts="" the="" word="" to="" all="" upper="" case="" and="" tosses="" away="" any="" characters="" that="" are="" not="" alphabetical.="" however,="" do="" include="" any="" dashes!="" "-"="" these="" may="" occur="" in="" hyphenated="" words.="" the="" method="" returns="" the="" cleaned-up="" word.="" must="" use="" a="" single="" if="" statement="" and="" the="" keyword="" or.="" examples:="" cat's="" cats,="" forget-me-not="" forget-me-not="" def="" clean_up(word):="" w="" for="" char="" in="" word.upper():="" return="" w="" b.="" create="" an="" empty="" dictionary="" named="" d.="" open="" your="" text="" file="" and="" using="" nested="" for="" loops="" read="" in="" every="" line="" and="" word="" in="" the="" file.="" the="" split()="" command="" will="" help="" convert="" a="" line="" to="" a="" list="" of="" words.="" clean="" up="" each="" word="" (as="" you="" find="" it)="" and="" name="" it="" word.="" add="" each="" word="" to="" the="" dictionary="" d,="" being="" sure="" to="" update="" the="" value="" to="" keep="" count="" of="" the="" number="" of="" occurrences.="" the="" get()="" method="" may="" help.="" alert:="" this="" process="" may="" have="" created="" the="" empty="" word="" ''.="" delete="" that="" from="" your="" dictionary="" using="" del.="" your="" magic="" letter="" is="" the="" first="" letter="" in="" your="" first="" name="" (in="" caps).="" my="" magic="" letter="" is:="" ____="" c.="" find="" the="" 3-letter="" word="" that="" starts="" with="" your="" magic="" letter="" and="" has="" the="" greatest="" frequency.="" if="" there="" are="" none,="" then="" allow="" more="" than="" 3="" letters.="" __="" __="" __="" d.="" how="" many="" words="" start="" with="" your="" magic="" letter="" and="" only="" appear="" once="" in="" the="" story?="" __="" __="" __="" e.="" how="" many="" words="" appear="" 100="" or="" more="" times="" in="" the="" story?="" __="" __="" __="" 3.="" read="" and="" plot="" simulated="" data="" provided="" in="" a="" csv="" file.="" a.="" choose="" your="" datafile.="" if="" your="" last="" name="" starts="" with="" a-g="" you="" must="" choose="" data1.csv="" if="" your="" last="" name="" starts="" with="" h-o="" you="" must="" choose="" data2.csv="" if="" your="" last="" name="" starts="" with="" p-s="" you="" must="" choose="" data3.csv="" if="" your="" last="" name="" starts="" with="" t-z="" you="" must="" choose="" data4.csv="" i="" am="" using="" the="" data="" file="" numbered="" :="" ____="" each="" data="" file="" contains="" two="" columns="" of="" data.="" the="" first="" column="" is="" the="" time="" t="" in="" minutes.="" the="" second="" column="" is="" the="" intensify="" of="" a="" function="" that="" seems="" to="" fit="" a="" biexponential="" curve.="" alert:="" there="" is="" a="" header="" row!="" a.="" using="" csv.reader(),="" read="" in="" all="" the="" data.="" be="" sure="" to="" skip="" the="" header="" row.="" append="" all="" the="" time="" values="" to="" a="" list="" named="" time.="" append="" all="" the="" y-values="" to="" a="" list="" named="" y.="" print="" out="" the="" sum="" of="" the="" y-values.="" _="" _="" _="" _="" _="" _="" _="" _="" _="" _="" b.="" find="" the="" biggest="" y-value.="" biggest="" y="" is:="" _="" _="" _="" _="" _="" _="" _="" _="" _="" _="" c.="" complete="" this="" method="" to="" automatically="" find="" the="" point="" with="" the="" maximum="" y-value.="" you="" should="" already="" have="" two="" lists="" named="" time="" and="" y.="" tmax,="" ymax="0," 0="" #="" stub="" values="" for="" n="" in="" range(len(time)):="" #="" get="" the="" next="" time="" and="" y="" values="" #="" test="" if="" this="" y="" is="" bigger="" than="" ymax="" (so="" far)="" and="" update="" d.="" using="" matplotlib,="" create="" a="" plot="" of="" your="" data="" points.="" show="" each="" point="" as="" a="" circle="" with="" a="" blue="" outline="" and="" filled="" with="" yellow.="" e.="" add="" the="" title="" "biexponential="" data".="" fill="" in="" the="" maximum="" point="" in="" red="" and="" make="" it="" a="" little="" larger="" than="" the="" other="" data="" points.="" paste="" your="" completed="" plot="" to="" the="" right.="" 4.="" curve-fitting="" your="" data="" with="" a="" biexponential="" your="" data="" from="" the="" previous="" exercise="" is="" exactly="" fitted="" by="" a="" biexponential="" curve="" of="" the="" form:="" a.="" you="" should="" already="" have="" two="" lists="" named="" time="" and="" y="" containing="" the="" 101="" data="" points="" from="" the="" previous="" exercise.="" be="" sure="" to="" complete="" that="" exercise="" before="" attempting="" this="" one.="" write="" the="" code="" to="" import="" curve_fit="" from="" the="" scipy="" module="" and="" also="" import="" numpy="" and="" give="" it="" the="" shorter="" name="" np.="" b.="" complete="" the="" method="" f(t,*p)="" so="" it="" returns="" the="" value="" of="" the="" biexponential="" function="" at="" time="" t:="" must="" use="" the="" numpy="" module="" for="" the="" exponential="" function,="" and="" not="" the="" math="" module.="" def="" f(t,="" *p):="" c.="" complete="" this="" single="" line="" by="" calling="" curve_fit="" to="" return="" the="" optimal="" parameters="" popt="" and="" the="" covariance="" pcov="" for="" these="" parameters.="" the="" data="" points="" are="" in="" the="" lists="" named="" time="" and="" y="" containing.="" explicitly="" provide="" a="" guess="" for="" p0.="" popt,="" pcov="d." record="" the="" best-fit="" parameters="" for="" your="" data="" here.="_" _="" _="" _="_" _="" _="" _="_" _="" _="" _="_" _="" _="" _="" hint:="" all="" four="" parameters="" will="" be="" integers,="" and="" some="" are="" negative.="" you="" will="" need="" to="" try="" other="" initial="" guesses="" than="" p0="[1," 1,="" 1,="" 1]="" if="" this="" default="" guess="" does="" not="" produce="" an="" exact="" integer="" fit="" with="" a="" covariance="" matrix="" with="" all="" elements="" equal="" to="" zero.="" 5.="" a="" class="" of="" animals!="" (5="" points)="" after="" reading="" through="" chapter="" 11,="" you="" should="" be="" easily="" able="" to="" complete="" this="" problem.="" animals="" need="" food.="" let's="" create="" a="" dictionary="" describing="" the="" available="" food="" items="" and="" their="" nutritional="" value.="" import="" random="" food_value="{}" #="" dictionary="" of="" food="" items="" and="" their="" life-energy="" value="" plants="{"grass":1," "weeds":1,="" "carrots":4,="" "lettuce":2,="" "nut":5}="" meat="{"hot" dog":10,="" "steak":20,="" "fish":15,="" "burger":15}="" 1.="" the="" dictionary="" named="" food_value="" is="" currently="" empty.="" add="" some="" code="" so="" it="" holds="" the="" values="" for="" all="" the="" plants="" and="" meats.="" must="" not="" use="" any="" :'s="" in="" your="" answer.="" ok="" to="" use="" two="" statements.="" each="" animal="" has="" a="" name="" and="" a="" life_energy.="" the="" animal="" will="" die="" if="" its="" life="" energy="" falls="" to="" zero.="" class="" animal(object):="" def="" __init__(self,="" name="None," life_energy="10):" self.name="name;" self.life_energy="life_energy" 2.="" complete="" the="" eat()="" method,="" which="" is="" inside="" the="" class="" body.="" when="" the="" food="" item="" is="" eaten,="" the="" animal's="" life_energy="" is="" increased="" by="" the="" amount="" recorded="" in="" the="" dictionary="" food_value.="" def="" eat(self,="" food):="" #="" an="" animal="" can="" eat="" food.increase="" its="" life_energy.="" 3.="" complete="" the="" is_alive()="" method,="" which="" is="" inside="" the="" class="" body.="" an="" animal="" is="" only="" alive="" provided="" its="" life_energy=""> 0. Must not use an if statement. Go directly to the return statement. def is_alive(self): # Is the animal still alive? Finding food requires some effort or cost. This method decreases the animal's life_energy when it exerts an effort. Given for free. The max command keeps the life-energy from becoming negative. Given for free. # decreases the life_energy by the cost of an effort. def work(self, cost): self.life_energy = max(0, self.life_energy - cost) if __name__ == "__main__": # Demo of the Animal class Enter your magic number from Question 1 M = _ _ _ _ random.seed(M) # 4. Construct a goat named "Billy" and give Billy 50 life units. goat = In the for loop below, your goat Billy goes searching for food once each day of the week. This always costs him 10 life_energy units for the effort. Each day he encounters one random item of food, gaining its life energy but costing ten units for the effort
Answered Same DayJun 08, 2021THE101

Answer To: ENGR-131 Name : _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Spring 2020 first last Your Magic...

Arun Shankar answered on Jun 09 2021
162 Votes
f = open("data.csv", "r")
for x in f:
print(x)
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here