In order to complete this assignment, you will need to download the following .csv file: roster_extended.csv This file contains a header row and a roster of 13 names. Additional test...

1 answer below »
See attachments.


In order to complete this assignment, you will need to download the following .csv file: roster_extended.csv This file contains a header row and a roster of 13 names.  Additional test file: newroster.csv Write a program that asks the user for the name of a file (assume that the user will give you a .csv file formatted similar to roster_extended.csv and newroster.csv). The user could give you ANY file name, so make sure your program is flexible enough to take in any .csv file with the roster format. The goal of your program is to save the given roster AND additional user-input roster entries to a FORMATTED TEXT (.txt) file. Do not modify the original file .csv file. The user should interact with the program in the following way: (example 1) Hello. Please enter a roster file: roster_extended.csv There are 13 names in this file. Would you like to enter additional names? (Y/N) Y How many more names? 2 ----- Person 1 ----- First Name: Spongebob Last Name: Squarepants Age: 33 Occupation: fry cook Height (in inches): 50 Weight (in pounds): 100 Lifestyle (1-sedentary, 2-moderate, 3-active): 3 ----- Person 2 ----- First Name: Patrick Last Name: Star Age: 35 Occupation: unemployed Height (in inches): 50 Weight (in pounds): 100 Lifestyle (1-sedentary, 2-moderate, 3-active): 3 ------------------------- Save new roster file as: roster_extended2.txt File saved! (example 2) Hello. Please enter a roster file: roster_extended.csv There are 13 names in this file. Would you like to enter additional names? (Y/N) N ------------------------- Save new roster file as: roster_extended.txt File saved! (example 3) Hello. Please enter a roster file: roster_extend.csv ERROR, FILE DOES NOT EXIST. Please enter a roster file: roster_extended.csv There are 13 names in this file. Would you like to enter additional names? (Y/N) Y How many more names? 1 ----- Person 1 ----- First Name: Superlongnamethatyouwillhavetoconsider Last Name: Alsodontassumethattherosterfilewillhavelongnames Age: 99 Occupation: extremelylongoccupationtitle Height (in inches): 76 Weight (in pounds): 325 Lifestyle (1-sedentary, 2-moderate, 3-active): 3 ------------------------- Save new roster file as: roster_extended.txt File saved! Note in example 2, the user might enter the wrong file name. You only need to re-prompt for the correct file name once. Thereafter, you may assume that the user will follow the rules and enter values that make sense (e.g. correct 2nd-attempt file name, numeric value for height and weight, 1-3 for lifestyle, etc.) When saving the text file there should be a header line (similar to the roster_extended.csv file but with a different format). However, the number of spaces left for the first name, last name, and occupation will vary depending on the longest first name, last name, and occupation in your roster. Include all names from the csv roster and from the user input. The spacing in your newly written .txt file should be as follows: · x spaces for the first name (where x is the number of characters in the longest first name or 9 if all names are less than 9 characters in length), · y spaces for the last name (where y is the number of characters in the longest last name or 8 if all names are less than 8 characters in length), · 3 spaces for age, · z spaces for occupation (where z is the number of characters in the longest occupation or 10 if all occupations are less than 10 characters in length),  · 5 spaces for height in feet and inches (62 should be 5'2") · 3 spaces for weight, and · 9 spaces for activity level · AND one space in between each element Note, that this new roster file has three columns (sedentary, moderate, active), which you will need to combine into one "Lifestyle" column when you create your text file. Text should be right-aligned. After running the program, the start and end of your text file should look like... FirstName LastName Age Occupation Ht Wt Lifestyle Anna Barbara 35 nurse 5'3" 129 moderate ........(more names)........ Eric Wolfeschlegelsteinhausenbergerdorff 38 data analyst 5'8" 158 moderate Lucy Xi 49 professor 5'9" 161 moderate Yolanda Zachary 58 secretary 5'10" 164 sedentary   Keep in mind roster_extended.csv is only an example, so a long name like "Wolfeschlegelsteinhausenbergerdorff" might NOT be a name in the roster file. In addition, the user may add an even longer name to the file. Make sure your program is able to adjust accordingly.
Answered 2 days AfterFeb 06, 2021

Answer To: In order to complete this assignment, you will need to download the following .csv...

Neha answered on Feb 06 2021
143 Votes
import pandas as pd
print("Hello")
file = input("please enter a roster file:")
df = pd.read_csv(f
ile)
df.to_csv('xxx.txt', sep='\t', index=False)
firstSpace = " "
lastSpace = " "
occupSpace = " "
firstName = df['first'].tolist()
res = max(len(ele) for ele in firstName)
if res >9:
firstSpace = firstSpace*res
else:
firstSpace = firstSpace*9
lastName = df['last'].tolist()
res = max(len(ele) for ele in lastName)
if res >8:
lastSpace = lastSpace*res
else:
lastSpace = lastSpace*8
occup = df['occupation'].tolist()
res = max(len(ele) for ele in occup)
if...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here