Please use python 3 programming language
Write a function that gets a string representing a file name and a list. The function writes the content of the list to the file. Each item in the list is written on one line. Name the function WriteList. If all goes well the function returns true, otherwise it returns false.
Write another function, RandomRange that takes an integer then
it returns a list of length n, where n is an integer passed as an
argument, and the numbers in the list are random numbers in the
range 1 to n inclusive.
Assume that n > 0.
For example, if the user enters 50, the RandomRange returns 50
numbers where each number is randomly generated that is >= 1 and
<= 50.
Then write code for main, to get the the first input for the
RandomRange function then gets the input needed for the WriteList,
then call the function.
Call main.
Hi,
The following is the code for RandomRange and WriteList function
according to the given instructions. I have included comments
inline with the code for your reference.
I hope this answer helps you.
//Code: randfilewrite.py
import random
def RandomRange(size):
"""
Function to generate and return a list of given size. Each of the
elements are random numbers between the range 1 to given
number.
"""
rand_list = []
for i in range(size):
# Get a random number between 1 and size (inclusive)
r = random.randrange(1, size+1)
# Add to the list
rand_list.append(r)
#Return the list
return rand_list
def WriteList(list_values):
"""
Function to write the elements of the list to a file -
mylist.txt
"""
#Open the file in write mode
out_file = open("mylist.txt", "w")
#Iterate the list
for val in list_values:
#Write each element in different line to the file
out_file.write(str(val) + "\n")
out_file.close()
def main():
"""
Main method to get user's input for List size and invoke
RandomRange and WriteList methods
"""
val = input("Enter a number: ")
rand_list = RandomRange(int(val))
print("List with Random nos: " + str(rand_list))
print("Writing to file - mylist.txt")
WriteList(rand_list)
if __name__ == "__main__":
main()
### Output


Please use python 3 programming language Write a function that gets a string representing a file...
Python: Write a function named "filter_rows" that takes a string as a parameter representing the name of a CSV file with 5 columns in the format "<string>,<int>,<int>,<int>,<int>" and writes a file named "invite.csv" containing the rows from the input file where the value in the fifth column is greater than 101
PYTHON Programming short Questions: 1. Write a function takes as input name (string) and age (number) and prints: My name is <name> and I am <age> years old(where name and age are the inputs) 2. Write a function that takes as input a and b and returns the result of: ??ab 3. Write a function that takes as input a and b and returns the result of: ??ab if it is valid to divide a and b 4. Write a...
Write the code in python programming Language String Statistics: Write a program that reads a string from the user and displays the following information about the string: (a) the length of the string, (b) a histogram detailing the number of occurrences of each vowel in the string (details provided below), (c) the number of times the first character of the string occurs throughout the entire string, (d) the number of times the last character of the string occurs throughout the...
Use
c++ as programming language. The file needs to be created ourselves
(ARRAYS) Write a program that contains the following functions: 1. A function to read integer values into a one-dimensional array of size N. 2. A function to sort a one-dimensional array of size N of integers in descending order. 3. A function to find and output the average of the values in a one dimensional array of size N of integers. 4. A function to output a one-dimensional...
For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...
PYTHON: Write a function that takes, as an argument, the name of a file, fileName, and an integer n between -750 and 750 (inclusive). Your program should verify that n is an integer in the correct range. If it is not, it should return the string “Your integer is out of range.” If it is in the correct range, your program should open (and read through) the file specified, and return the number of values in the file that are...
Python Programming language Write the following functions: getNumInRange(prompt, min, max) - gets a number from the user within the specified range, prompting with 'prompt' calcAvg(values) - calculates and returns the average from a supplied list of numeric values menu(somelist) - creates a numbered menu from a list of strings. Then, have the user select a valid choice (number), and return it. Use the getNumInRange() funtion to do this. getAlbum() - prompts the user for information to populate a dictionary representing...
Python Programming Assignment: Write a function to take a string S that returns True if the letters are in ascending order and False otherwise. To do this go over each letter and check that it is less than the letter that precedes it. Then write a function main that gets one input from the user, then if passing that input to the function above returns True, then show "String is in order", otherwise show " String is unordered".
Please use python Programming Language: Select one of the following topics: Band Character Account Create a class based on your chosen topic. Make sure to include at least four attributes of varying types, a constructor, getters/setters for each attribute w/input validation, a toString, a static attribute, and a static method. Then, create a function (outside of your class) that connects to a text file which should contain the attributes of several objects. Read the data from the file, use the...
In python Programming Exercise 1 Write a function that will have a list as an input, the task of the function is to check if all the elements in the list are unique,( i.e. no repetition of any value has occurred in the list), then the function returns true otherwise it returns false. Your program should include a main method that call the method to test it. Algorithm Analysis For the function you implemented in part 1, please calculate T(n),...