Question

In: Computer Science

Suppose that the file inData.txt contains the following data: 10.20 5.35 15.6 Randy Gill 31 18500...

Suppose that the file inData.txt contains the following data:

10.20 5.35

15.6

Randy Gill 31

18500 3.5

A

The numbers in the first line represent the length and width, respectively, of a rectangle. The number in the second line represents the radius of a circle. The third line contains the first name, last name, and the age of a person. The first number in the fourth line is the savings account balance at the beginning of the month, and the second number is the interest rate per year. (Assume that π = 3.1416.) The fifth line contains an uppercase letter between A and Y (inclusive). Write statements so that after the program executes, the contents of the file outData.txt are as shown below. If necessary, declare additional variables. Your statements should be general enough so that if the content of the input file changes and the program is run again (without editing and recompiling), it outputs the appropriate results.

Rectangle:

Length = 10.20, width = 5.35, area = 54.57, parameter = 31.10

Circle:

Radius = 15.60, area = 764.54, circumference = 98.02

Name: Randy Gill, age: 31

Beginning balance = $18500.00, interest rate = 3.50

Balance at the end of the month = $18553.96

The character that comes after A in the ASCII set is B


Solutions

Expert Solution

f=open("inData.txt",'r')

p=open("outData.txt",'a')

p.write("Rectangle:\n")

index=0

pi=3.1416

for line in f.readlines():

if(index==0):

l,w=line.strip().split(" ")

l=float(l)

w=float(w)

area=round(l*w,2)

parameter=round(2*(l+w),2)

p.write("Length = "+str(l)+", width = "+str(w)+", area = "+str(area)+", parameter = "+str(parameter)+" Circle.\n")

elif(index==1):

r=line.strip()

r=float(r)

area=round(pi*r*r,2)

circumference=round(2*pi*r,2)

p.write("Radius = "+str(r)+", area ="+str(area)+", circumference ="+str(circumference)+"\n")

elif(index==2):

fname,lname,age=line.strip().split(" ")

p.write("Name:{} {}, age:{}\n".format(fname,lname,age))

elif(index==3):

balance,interest=line.strip().split(" ")

balance=float(balance)

interest=float(interest)

value=((interest/100*balance)/12)+balance

p.write("Beginning balance=${0:.2f},interest rate={1:.2f}\n".format(balance,interest))

p.write("Balance at the end of the month=${:0.2f}\n".format(value))

elif(index==4):

char=line.strip()

a=ord(char)

p.write("The character that comes after {} in the ASCII set is {}".format(char,chr(a+1)))

index=index+1

#output:


Related Solutions

If the file circuit.txt contains the following data
Exercise 2: If the file circuit.txt contains the following data 3.0             2.1 1.5             1.1 2.6             4.1 The first column is voltage and the second column is the electric current. Write program that reads the voltages and currents then calculates the electric power (P) based on the equation: Voltage     Current        Power 3.0             2.1              (result) 1.5             1.1              (result) 2.6             4.1              (result)                         P = v * i Write your output to the file results.txt with voltage in the first, current in the second...
Suppose that we are using extendable hashing on a file that contains records with the following...
Suppose that we are using extendable hashing on a file that contains records with the following search-key values: (2, 3, 5, 7, 11, 17, 19, 23, 29, 31). Show the final extendable hash structure for this file if the hash function is h(x) = x mod 8 and buckets can hold three records. Recall that: 1. the bucket address table is indexed by the prefix of the binary representation of h(x). 2. Initially i = 0, i.e. the prefix consists...
Use the data in the Mod8-2Data file to answer the following questions. The data contains information...
Use the data in the Mod8-2Data file to answer the following questions. The data contains information from a car seat manufacturer on the age of machine (in months) and the cost of repairs (in 10s of $). Run the regression in Minitab and show the regression line on a scatter plot. Assume a level of significance of 5%. Age Repairs10 110 32.767 113 37.668 114 39.252 134 44.314 93 34.262 141 47.616 115 32.474 115 33.898 115 43.345 142 52.637...
The file P02_35.xlsx contains data from a survey of 500 randomly selected households. a. Suppose you...
The file P02_35.xlsx contains data from a survey of 500 randomly selected households. a. Suppose you decide to generate a systematic random sample of size 25 from this population of data. How many such samples are there? What is the mean of Debt for each of the first three such samples, using the data in the order given? b. If you wanted to estimate the (supposedly unknown) population mean of Debt from a systematic random sample as in part a,...
Assume there is a file called "mydata". each line of the file contains two data items
how do you read in a file in JAVA Assume there is a file called "mydata". each line of the file contains two data items: hours and rate. hours is the represented by the number of hours the worker worked and rate is represented as hourly rate of pay. The first item of data is count indicating how many lines of data are to follow.Methodspay- accepts the number of hours worked and the rate of pay. returns the dollor and cents...
The data file contains displacement (in mm)-load (in N) data for a mechanical test that was...
The data file contains displacement (in mm)-load (in N) data for a mechanical test that was conducted on an unknown metal. The initial length and diameter of the specimen are also given. a. (5 pts.) Using the data and a computer program (such as Excel), create an engineering stress-engineering strain graph with proper labels. The stress axis should be in the units of MPa. You do not need to show your spreadsheet or software code used to make the graph....
In the Excel data file, the tab labeled Question 1 contains data on the number of...
In the Excel data file, the tab labeled Question 1 contains data on the number of times boys and girls raise their hands in class. Conduct the t-test: Two-Sample Assuming Equal Variances. Males 9,8,4,9,3,8,10,8,9,10,7,6,12 Females 3,5,1,2,6,4,3,6,7,9,7,3,7,6,8,8 a. What is the null hypothesis? b. What is the research hypothesis? c. Why run a Two-Sample Assuming Equal Variances t-test? d. Interpret the findings. What are the results of the hypothesis test? Can you reject the null hypothesis?
The accompanying data file contains 20 observations for t and yt.
The accompanying data file contains 20 observations for t and yt. t 1 2 3 4 5 6 7 8 9 10 yt 12.1 12.2 9.3 12.8 8.6 9.3 14.3 12.1 11.5 15.1 t 11 12 13 14 15 16 17 18 19 20 yt 13.5 9.8 9.6 14.5 14.9 12.4 11.2 8.8 11.8 10 a. Discuss the presence of random variations. The smoother appearance of the graph suggests the presence of random variations. The smoother appearance of the graph...
Consider a text file that you will create named “employees.txt”. The file contains data organized according...
Consider a text file that you will create named “employees.txt”. The file contains data organized according to the following format:John Smith 10 15Sarah Johnson 40 12Mary Taylor 27 13Jim Stewart 25 8For instance, “John” is the first name, “Smith” is the last name, “10” is the number of hours per week, and “15” is the hourly rate.Write a program that computes the weekly salary of each employee. The program prints the first name, last name, and weekly salary of each...
The accompanying data file contains 20 observations for t and yt. The data are plotted below....
The accompanying data file contains 20 observations for t and yt. The data are plotted below. t 1 2 3 4 5 6 7 8 9 10 yt 10.8 14.1 10.3 10.9 11.3 13.5 10.7 9.2 8.8 12 t 11 12 13 14 15 16 17 18 19 20 yt 9.8 11 15.1 12.5 12.9 12.3 9 14.9 10.1 11.9 b-1. Use the exponential smoothing method to make forecasts with α = 0.2. (Round intermediate calculations to at least 4...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT