The programs should be saved in Python script file (.py extension). 1) Random race: Imagine two runners are competing in a race. They both begin at the starting line (step 0). The finish line is at...

1 answer below »
I have 7 programming assignments I need done in python 3.I would prefer if one person did them since you can tell the difference when different people write a program as every has their own pattern and style.If you need examples of similar code for these assignments from my class,let me know because I don't want complex code I haven't learnt yet in my programs.


The programs should be saved in Python script file (.py extension). 1) Random race: Imagine two runners are competing in a race. They both begin at the starting line (step 0). The finish line is at step 100. Use a while loop to give each runner a turn in the race. Each turn they take, they advance a random integer number of steps from 1 to 5 ahead. The while loop should continue as long as neither runner has reached the finish line. In the while loop, print the new position for each runner. For example, “Runner 1 is now at step” and the actual step value. Once the while loop ends, use an if statement to print which runner won the race. To use the random functions, import random # then use random.randint() or from random import randint # then use randint(). 2) Create a long string of text. Let the user input a search term (could be a single character, word or phrase). If the search term is not found, print a message that indicates it was not found. If the search term is found, • print the number of times it is found in the full text • print the position of the first occurrence of the search term 2 b) Let the user input a long string of text. Print the full string entered then check each character individually using a loop. If the character is numeric, print the character and the phrase “is numeric”. If the charcter is lowercase, print the character and the phrase “is lower”. If the character is uppercase, print the character and the phrase “is uppercase”. 3) Write a function that takes in a string and returns a dictionary with the letter frequencies in the string. For example, an input string of "Hello" would generate a dictionary with the following entries { "H": 1, "e": 1, "l": 2, "o": 1 } 3 b) Write a function that takes in a file and returns a dictionary with the word frequencies in the file. 4) Implement solutions 1, 2 and 4 in Section 2.4 – An Anagram Detection Example from the Problem Solving with Algorithms and Data Structures online text. (http://interactivepython.org/runestone/static/pythonds/AlgorithmAnalysis/AnAnagramDetectionExample.html) • Import the time module and use its time() function to get the running time of each of these three algorithms with these parameters: · Run with a string of length 10. · Run with a string of length 100. · Run with a string of length 1000. You can modify this code from the Car class designed to generate a random VIN of length 16 to generate a random string for these tests. characterSet = ascii_uppercase + digits length = 16 VIN = "".join([choice(characterSet) for x in range(length)]) 5) Implement a DigitalEvidence class in Python. The class will model a single piece of digital evidence in either a criminal or civil case. The exact data members included are up to you, but could be similar to the information captured on a chain of custody form. Include __init__ and __str__ methods, as well as methods to retrieve, set and/or process the data in the class. Test your class in a main.py file by creating a digital evidence object and testing all the methods you’ve defined in the class. References for digital evidence and chain of custody documentation. • https://www.nij.gov/topics/forensics/evidence/digital/Pages/welcome.aspx • https://resources.infosecinstitute.com/category/computerforensics/introduction/areas-ofstudy/ legal-and-ethical-principles/chain-of-custody-in-computer-forensics/ • https://www.oreilly.com/library/view/computer-evidencecollection/ 9781584506997/9781584506997_app01.html 6) Instructions: Add the following functions into the unsorted Linked List class started in class. I sent the code for the main.py and linkedlist.py in two other word documents since the Linked List is called from the main program. pop() Remove and return the value of the last item in the list. You could consider adding a tail data member to the linked list that will point to the last node, just as the head data member points to the first node in the list. If the list is empty, return None. index(item) Find and return the position in the list of the value sent in to the function. The position of the value in the first node would be 0. If the value is not in the list, return None. Test the functions in the main program by first creating a list and populating it with different values, then printing out the return values of the functions, e.g. print(pop()). Visualgo has visualizations for Linked Lists here: https://visualgo.net/en/list 7) Instructions: Read in a text file (at least a paragraph of text) and split the text into a list of individual words.Usetwo stacks,one for the whole words, and one for the characters in a word. Reverse the order of wordsin a text, as well as the order of the letters in each word. Print out the reversed text.For example, if the text were “Read in a text file.”, the output would be “.elif txet a ni daeR”. Visualgo has visualizations for Stackshere: https://visualgo.net/en/list Linked List class Node: def __init__(self, data): self.data = data self.nextnode = None def set_data(self, newdata): self.data = newdata def set_nextnode(self, newnext): self.nextnode = newnext def get_data(self): return self.data def get_nextnode(self): return self.nextnode class LinkedList: def __init__(self): self.head = None # check if empty def is_empty(self): return self.head == None # add a Node to front def add_front(self, data): temp = Node(data) temp.set_nextnode(self.head) self.head = temp # size of list def get_size(self): current = self.head count = 0 while current != None: count += 1 current = current.get_nextnode() return count # search def search(self, value): current = self.head found = False while current != None and not found: if current.get_data() == value: found = True else: current = current.get_nextnode() return found # remove def remove(self, value): current = self.head found = False previous = None while not found: if current.get_data() == value: found = True else: previous = current current = current.get_nextnode() if previous == None: self.head = current.get_nextnode() else: previous.set_nextnode(current.get_nextnode()) def print_list(self): current = self.head while current != None: print(current.get_data()) current = current.get_nextnode() class SortedLinkedList: def __init__(self): self.head = None def add(self, value): current = self.head previous = None stop = False while current != None and not stop: if current.get_data() > value: stop = True else: previous = current current = current.get_nextnode() temp = Node(value) if previous == None: temp.set_nextnode(self.head) self.head = temp else: temp.set_nextnode(current) previous.set_nextnode(temp) def search(self, value): current = self.head found = False stop = False while current != None and not found and not stop: if current.get_data() == value: found = True else: if current.get_data() > value: stop = True else: current = current.get_nextnode() return found def print_list(self): current = self.head while current != None: print(current.get_data()) current = current.get_nextnode() Main.py code from LinkedList import Node, LinkedList, SortedLinkedList nodeA = Node(50) print(nodeA.get_data()) print(nodeA.get_nextnode()) print('\n') myList = LinkedList() print(myList.is_empty()) print(myList.get_size()) print('\n') myList.add_front(100) myList.add_front(40) myList.add_front(75) myList.add_front(33) myList.print_list() print('\n') mySortedList = SortedLinkedList() mySortedList.add(100) mySortedList.add(40) mySortedList.add(75) mySortedList.add(33) mySortedList.print_list()
Answered Same DayApr 02, 2021

Answer To: The programs should be saved in Python script file (.py extension). 1) Random race: Imagine two...

Ximi answered on Apr 05 2021
149 Votes
#!/usr/bin/env python
# coding: utf-8
# In[12]:
#Random race
import random
runner1 = 0
runner2 = 0
while runner1 < 100 or runner2 < 100:
if runner1 >= 100:
print ("Runner 1 won")
break
elif runner2 >= 100:
print ("Runner 2 won")
break
else:
step = random.randint(1, 5)
runner1 += step
print ("Runner 1 step - {}".format(runner1))
step = random.randint(1, 5)
print ("Runner 2 step - {}".format(runner2))
runner2 += step

# In[1]:
#2) Find the term
string = "Hello world, I like python programming. I want to become a python backend developer"
term = input("Enter a search term: ")
print ("Number of times term occurred : {}".format(string.count(term)))
print ("First index of the term in string : {}".format(string.find(term)))
# In[3]:
#2 b)
string = input("Enter a long string : ")
print (string)
for char in string:
if char.isdigit():
print ("{} is numeric".format(char))
if char.islower():
print ("{} is lower".format(char))
if char.isupper():
print ("{} is upper".format(char))
# In[4]:
#3)
string = input("Enter a string : ")
freq = {char:string.count(char) for char in string}
print (freq)
# In[7]:
#3)
filename = input("Enter file name: ")
with open(filename, 'r') as f:
words = f.read().split()
freq = {word: ' '.join(words).count(word) for word in words}
print (freq)
# In[9]:
# 4)
def anagramSolution1(s1,s2):
alist = list(s2)
pos1 = 0
stillOK = True
while pos1 < len(s1) and stillOK:
pos2 = 0
found = False
while pos2 < len(alist) and not found:
if s1[pos1] ==...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here