Subjects
PRICING
TEST PREP
SIGN IN
Start Free Trial
Nitin M.
Undergrad at IIST., Asia's Second Space Science University; Tutoring for years
Tutor Satisfaction Guarantee
Python Programming
TutorMe
Question:

You are to create a Python program which can be used to perform some simple analysis of text files of various sizes. This program should first ask the user for the name of the file to be analysed and then read it and place the contents into a list. The text file will contain space separated words without any punctuation. Some words may be duplicated, in these cases, store every instance of the word. The program will then present a menu to the user, allowing them to choose from the options described below. The program should continue asking for actions until the user chooses to quit. In these functions, you must implement the sort or search functions yourself. Do not use the built-in sort or search functions. Option a: Print the number of words in the list. Option b: Print whether a given word is in the list (case insensitive). Option c: Print whether any word in the list has a given length. Option d: Print the number of case-sensitive instances of a given word in the list. Option e: Print the number of words with a given length in the list. Option f: Sort the words in the list alphabetically and print them. Option g: Sort the words in the list by word length and print them. Option h: Quit

Nitin M.
Answer:

def main(): filename = input('Enter a file name: ') linestring = open(filename, 'r').read() words=linestring.split(' ') menu() choice= input("Enter menu choice:\t") while choice != "h": if choice == "a": count(words) elif choice == "b": check(words) elif choice == "c": length(words) elif choice == "d": casecheck(words) elif choice == "e": lengthnum(words) elif choice == "f": sortalpha(words) elif choice == "g": sortlength(words) choice = input("Enter your choice:\t") print("\nApplication Exited") def menu(): print("Choose a number to continue:\t\n\ Select a to Print the number of words in the list.\n\ Select b to Print whether a given word is in the list (case insensitive).\n\ Select c to Print whether any word in the list has a given length.\n\ Select d to Print the number of case-sensitive instances of a given word in the list.\n\ Select e to Print the number of words with a given length in the list.\n\ Select f to Sort the words in the list alphabetically and print them.\n\ Select g to Sort the words in the list by word length and print them.\n\ Select h to Quit") #Option a def count(words): print("\nThe number of words in file is %d" % len(words)) #Option b def check(words): p=0 word = input('Enter the word to search for : ') while p<len(words): if word.lower() == words[p]: print("\n Word found ! : ", word) break p=p+1 #Option c def length(words): p=0 l = int(input('Enter the word length to search for : ')) while p<len(words): if len(words[p])==l: print("\nWord found !") print(words[p]) break p=p+1 #Option d def casecheck(words): p=0 count=0 word = input('Enter the word to search for : ') while p<len(words): if word== words[p]: count=count+1 p=p+1 print("\nWord found %d times !" % count) #Option e def lengthnum(words): p=0 count=0 l = int(input('Enter the word length to search for : ')) while p<len(words): if len(words[p])==l: count=count+1 p=p+1 print("\nWord length found %d times !" % count) #Option f def sortalpha(words): p=0 words=sorted(words,key=lambda s: s.lower()) while p<len(words): print(words[p]) p=p+1 #Option g def sortlength(words): p=0 words.sort(key = lambda s: len(s)) while p<len(words): print(words[p]) p=p+1 #Call main main()

MATLAB
TutorMe
Question:

Data from a tensile test is, as well as a script which loads and plots the data needs to be modified to add commands and control structures to the script in order to determine some material properties. (a) Using at least one control structure, write a code that can determine the largest value in any vector, and use this to determine the largest stress on the curve. This point is known as the ultimate tensile stress (UTS). Also, determine the corresponding strain for this stress. (b) Using at least one control structure, write a code that will find the first local maximum in a vector, and use this to determine the height of the initial spike on the curve. This is known as the yield stress. Also, determine the corresponding strain for this stress. (c) Plot the stress-strain curve with the Yield Stress and Ultimate Tensile Stress marked on the plot. Does it look as though the code has calculated the correct values? (d) Using at least one control structure, approximate the area under the stress-strain curve using the trapezoid rule. This is known as the toughness of the material.

Nitin M.
Answer:

%% Stress-Strain Curve Script clear all clc %% Importing data load('materials_data.mat') %% Determination of UTS max_stress=stress(1); for i=2:length(stress) if stress(i)>max_stress max_stress=stress(i); strain_uts=strain(i); end end fprintf( '\nThe ultimate tensile stress is %f.\n', max_stress) fprintf('The strain corresponding to UTS is %f.\n\n', strain_uts) %% Determination of Yield Stress for i=2:length(stress) yield_stress=stress(i); strain_ys=strain(i); if yield_stress>stress(i-1) && yield_stress>stress(i+1) break end end fprintf( 'The yield stress is %f.\n', yield_stress) fprintf('The strain corresponding to yield stress is %f.\n\n', strain_ys) %% Plot with points marked [a b]=findpeaks(stress,strain,'MinPeakProminence',9,'NPeaks',2,'MinPeakDistance',0.05); textout=sprintf('(%f,%f)',b(1),a(1)); findpeaks(stress,strain,'MinPeakProminence',9,'NPeaks',2,'MinPeakDistance',0.05) text(b(1),a(1),textout,'HorizontalAlignment','left') textout=sprintf('(%f,%f)',b(2),a(2)); text(b(2),a(2),textout,'HorizontalAlignment','center') title('Stress-Strain Curve for Steel Sample') xlabel('Strain') ylabel('Stress [MPa]') %% Determination of Toughness toughness=trapz(strain,stress); fprintf('The toughness is %f MPa.\n', toughness)

C Programming
TutorMe
Question:

This practice assignment is about loops.  The intention is for you to use a while loop, but the problem can also be solved with a for loop. The Problem Statement You and your roommates go through a lot of orange juice.  You've noticed that your roommate goes through more orange juice than you do.  And when they run out, they will take some of yours. You have been charging your roommate every time they take some of your orange juice.  But it feels a bit silly collecting 50 or 75 cents at a time from them. You’ve come up with a brilliant plan! Instead of charging them every time they take your orange juice, you’ll collect money from them after they have taken 10 dollars’ worth of juice. Program Setup Write a program to mimic this process.  Ask the user to enter the size (in ounces) of the juice containers you buy, as well as the price of those containers (in dollars). Then prompt the user to enter how many times the roommate took juice. Finally, read the amount the roommate took each time. Every time the total value of the juice equals or exceeds $10, print out “Your roommate owes you $10.00.” After all the numbers are entered, if the roommate owes any money, print out the value owed. Sample Run What is the weight (in oz.) of the original container of OJ? 64 What is the cost of the original container of OJ in dollars? 3.79 How many times did your roommate take your juice? 10 How much juice did your roommate take this time (in oz.)? 30 How much juice did your roommate take this time (in oz.)? 34 How much juice did your roommate take this time (in oz.)? 24 How much juice did your roommate take this time (in oz.)? 40 How much juice did your roommate take this time (in oz.)? 64 Your roommate owes you $10.00. How much juice did your roommate take this time (in oz.)? 64 How much juice did your roommate take this time (in oz.)? 64 How much juice did your roommate take this time (in oz.)? 18 Your roommate owes you $10.00. How much juice did your roommate take this time (in oz.)? 20 How much juice did your roommate take this time (in oz.)? 20 Your roommate owes you $2.38.

Nitin M.
Answer:

#include<stdio.h> int main() { float weight,rate,q,price=0.0; int times,i=0; printf("\n What is the weight (in oz.) of the original container of OJ?\n "); scanf("%f",&weight); printf("\n What is the cost of the original container of OJ in dollars?\n "); scanf("%f",&rate); printf("\nHow many times did your roommate take your juice?\n "); scanf("%d",&times); while(i<times) { printf("\nHow much juice did your roommate take this time (in oz.)?\n "); scanf("%f",&q); price+=(rate/weight)*q; if(price>=10.0) { printf("\nYour roommate owes you $10.00.\n"); price-=10; } i++; } if(price>0.0) { printf("\nYour roommate owes you $%f.\n",price); } return 0; }

Send a message explaining your
needs and Nitin will reply soon.
Contact Nitin
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.