Question: Can someone please write a program for the given algorithms in python without using import or libraries/ without making changes to the algorithms please ?
Can someone please write a program for the given algorithms in python without using import or libraries/ without making changes to the algorithms please ?
A1) START STEP:1 Read the given a list of numeric values stored in variable that is num_list STEP:2 Compute the maximum of numbers by using method max () STEP:3 Compute the minimum value of numbers using method min () STEP:4 Compute the mean value by calculating the sum of the list sum (num_list) and store in variable num_sum STEP:5 Divide the num_sum by len (num_ list) that is mean = num_sum/len (sum list) STEP:6 Then display the num list using that is print(num_list) STEP:7 Compute the median value by using method median = num_list[len(num_list)//2] C: If there are two numbers in the middle, compute the median as the average of the two numbers T: first_median = num_list[len(num_list)//2] second_median = num_list[len(num_list)//2-1] median = (first_median + second_median) /2 F: Display the num list value that is print(num_list) STEP:8 Compute the mode value of the list First calculate the frequency of each item data = collections. Counter(num_list) Data_list = dict(data) Display the items with frequency print(data_list) Find the highest frequency max_value = max (list (data. values ()) Mode val = [num for num freq in data_list. items () if freq == max_value] Print (the mode of the list is: +, . join (map (str, mode_val))) STOP
A2) START STEP:1 Take one paragraph and store it in one string variable STEP:2 Display the total number of characters by using function len () that is print (len ()) STEP:3 Display the number of characters not counting spaces by using function len () count ()
e.g., a_string = hello world number_of_letters = len(a_string) a_string. Count ()
print(number_of_letters)
STEP:4 Display the number of characters not including spaces and punctuations by using import re that is print (len (. join (re. findall(r[A-Z0-9a-z], string))))
STEP:5 Display the number of words by using split function that is split the string by whitespace
That is len (text. Split ())
STEP:6 Ask the user to enter any words separated by space that needs to need to be omitted
Define a variable omitted = (the, and, for, then) Then add the omitted words by using function tuple. (word. split (' '))
STEP:7 Count the words except the omitted words, using for loop
First define a variable and assign the value 0 that is totalWordsExceptOmitted = 0 for i in text. split (' '): if (i not in omitted and len(i) > 2): totalWordsExceptOmitted += 1
STOP
A3) START STEP:1 First define the course dictionary and file name For line in f use the line. rstrip (). split (",") function to strip line from right and split it by comma STEP:2 Enter 1 for query a course, enter 2 to add a new course or enter 3 to update title of a course choice = int (input ("Enter your choice: ")) STEP: 3 if choice is 1 then ask user to enter course number and store in variable subject_key and print the details of subject that is print (' Course Title) print (' Course Type) print (' Course Credit) STEP: 4 if choice is 2 then ask user to enter course number of the new course, enter title of the new course, enter type of the new course, and enter credit of the new course. Display new entry has been updated. Write the data by using method file. write(data) STEP: 5 if choice is 3: Ask user to enter course number then print details that is Display course Ask user to enter new title of the course use update () method to update it Then display title has been updated Then give the command file = open ("P3HW7.txt", 'wt') STEP: 6 After all changes, the algorithm should write the updated data back into the text file in the same comma delimited format for use at a later time take the variable c and assign value 0 for key course.keys(): subject_num=course[key]['Name'] subject_title=course[key]['Type'] subject_credit=course[key]['Credit'] data = key+','+ subject_num +','+ subject_title +','+ subject_credit fh. write(data) c=c+1 if c nl = fh. write(nl) except: print ("No such course number found") STOP
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
