Question

I need assistant with the following coding please! It has to be in Python. 2) A...

I need assistant with the following coding please! It has to be in Python.

2) A file name is given by users. Assume that the file name is in fully-qualified-path. With this file name, the function is invoked.

For example, it runs as follows:

Enter file name: C:\\Users\\jyoon\\Desktop\\tempFile.data

45.00° in F is 7.22° in C

23.00° in c is 73.40° in F

11.00° in C is 51.80° in F

76.00° in F is 24.44° in C

88.00° in F is 31.11° in C

12.00° in F is -11.11° in C

1.00° in C is 33.80° in F

Note that the file tempFile.data in the C:\Users\jyoon\Desktop directory contains

45 F

23 c

11 C

76 F

88 F

12 F

1 C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def c_to_f(celsius):

return round((9*celsius)/5 + 32,2)

def f_to_c(fahrenheit):

return round(((fahrenheit-32)*5)/9 , 2)

infile = open("tempFile.data", "r")

for f in infile.readlines():

if len(f) == 0:

    continue

f = f.rstrip('\n')

f = f.split(" ")

if f[1] == 'F' or f[1] == 'f':

    print(f[0],"° in F is",f_to_c(float(f[0])),"° in C")

elif f[1] == 'C' or f[1] == 'c':

    print(format(float(f[0]),'.2f'),"° in C is",c_to_f(float(f[0])),"° in F")

   

===============================================

SEE OUTPUT/ IMAGE FOR INDENTATION

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
I need assistant with the following coding please! It has to be in Python. 2) A...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PYTHON CODING HELP: BELOW ARE THE STEPS I NEED HELP WITH PLEASE. :) First create a...

    PYTHON CODING HELP: BELOW ARE THE STEPS I NEED HELP WITH PLEASE. :) First create a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots ... and have it be in the same directory as the Python program you are coding for this assignment. IMPORTANT: Your program should work with any size file. It should work with 100 items listed or with no items in the file! Write a Python program that ... 1....

  • this is a java course class. Please, I need full an accurate answer. Labeled steps of...

    this is a java course class. Please, I need full an accurate answer. Labeled steps of the solution that comply in addition to the question's parts {A and B}, also comply with: (Create another file to test the class and output to the screen, not an output file) please, DO NOT COPY others' solutions. I need a real worked answer that works when I try it on my computer. Thanks in advance. Write the definition of the class Tests such...

  • Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART...

    Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{    int day;    int month;    int year; }; /** This structure is to store the size of the box and it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT