In python write a module named randStr.py that has 3 functions.
Each function has an optional second parameter to set a particular
seed.
1) randWord accepts a string and will return a random word from
that string (return value is string).
2) strMixer will randomly change words inside the string and
returns a string
-- If the string is only one word, then it will mix the letters of
the word and return the mixed word as a string
3) randIntForWord accepts a word and then returns a random integer
between 0 and 100,000; the same word should return the same random
integer.
Import the 3 functions in the main file and call each of them 5
times (with and without seed).
If the module is called directly, print the following
message:
"Sorry, but this module can only be imported!"
(Note, you can add a second file to a project by clicking on the
document above the line number on the left side)
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.
If you are satisfied with the solution, please rate the answer. Let me know for any help with any other questions.
Thank You !
===========================================================================
import random
def randWord(sentence):
words = [word.strip() for word in sentence.strip().split()]
return random.choice(words)
def strMixer(sentence):
words = [word.strip() for word in sentence.strip().split()]
if len(words)==1:
letters = [letter for letter in sentence]
random.shuffle(letters)
return ''.join(letters)
else:
random.shuffle(words)
return ' '.join(words)
def randIntForWord(word):
hash_value = hash(word)
return hash_value%(100001)
=======================================================================
from randStr import randWord,randIntForWord,strMixer
def main():
sentence = 'The brown fox just jumped over the lazy dog '
for _ in range(3):
print('randWord: {}'.format(randWord(sentence)))
for _ in range(3):
print('strMixer(): {}'.format(strMixer(sentence)))
word = 'America'
for _ in range(3):
print('strMixer(): {}'.format(strMixer(word)))
words = [word for word in sentence.split()]
for _ in range(3):
for word in words:
print('randIntForWord({}): {}'.format(word,randIntForWord(word)))
main()
=======================================================================



In python write a module named randStr.py that has 3 functions. Each function has an optional...
1. Write a function to keep asking the user for names in the form of strings, sort alphabetically and store these names into a text file named names.txt 2. Write a function that accepts a string as the argument, removes all alphabetical letters from the string, and returns it 3. Write a function that accepts a file name in the form of a string as the argument. Assume the text file contains single-digit numbers and letters. Read the entire contents...
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function named capital_letter that accepts a string as an argument and checks if each word in the string begins with a capital letter. If so, the function will return true, otherwise, return false. Please see the outcome below: Outcome number 1: Enter a string: Python Is Really Fun! True Sample run number 2: Enter a string: i Love Python False Note: Try to keep this...
Create a Python script file called hw.py. Then import the module
random:
from random import *
Thanks in advance!
Ex. 1. Write a function called cleanLowerWord that receives a string as a paramcter and retums a new string that is a copy of the parameter where all the lowercase letters are kept as such, uppercase letters are converted to lowercase, and everything else is deleted. For example, the function call cleanLowerWord("Hello, User 15!") should return the string "hellouser". For this,...
"PYTHON" 1. a. Create a file (module) named camera_picture.py. b. Write a function, take_picture_effect, that takes two parameters, the filename and an effect. c. Take a picture with the filename and effect. Use camera.effect to set the effect. Use help(PiCamera) to find the effects which you can apply. d. Create a second file use_camera.py. e. Import the take_picture_effect function from the camera_picture module. f. Prompt the user for the filename. g. Prompt the user for the image_effect. help(PiCamera) to see...
Python 3 code Write a function named coinflip that accepts an input called flips. The function should sim-ulate flipping a coin flips times. The function should return True if the coin was the same result for every flip. You can assume the function receives a positive integer as input. Write a second function named simulation that runs trials of the coin flip experiment. simulation should accept two parameters: the number of trials, and the number of coin flips to do...
Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to". The file must be named: words_in_both.py...
using c++ program
write this program without the optional exercise
3. Word Counter Write a function that accepts a pointer to a C-string as an argument and returns the number of words contained in the string. For instance, if the string argument is "Four score and seven years ago” the function should return the number 6. Demonstrate the function in a program that asks the user to input a string and then passes it to the func tion. The number...
average_value_in_file / Python 3.x: Your assistance is appreciated, thank you! Write a function named average_value_in_file that accepts a file name as a parameter and reads that file, assumed to be full of numbers, and returns the average (mean) of the numbers in that file. The parameter, filename, gives the name of a file that contains a list of numbers, one per line. You may assume that the file exists and follows the proper format. For example, if a file named...
python In a program, write a function named roll that accepts an integer argument number_of_throws. The function should generate and return a sorted list of number_of_throws random numbers between 1 and 6. The program should prompt the user to enter a positive integer that is sent to the function, and then print the returned list.
Python 3.6
Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two parameters: 1. inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file The input file exists when wordLengths is called; wordLengths must create the file outFile. The input file contains only letters and white space For each line of the input file, wordLengths should identify the length of the longest word...