Question

Give a problem statement that requires you to develop a Python program that meets the following...

Give a problem statement that requires you to develop a Python program that meets the following requirements

  • (2 EC points) The program reads data from a text file and then assigns it to a string variable
  • (2 EC points) The program defines and calls at least one function other than main()
  • (2 EC points) The program uses a multi-way branch (if, followed by a number of elifs, followed by else)
  • (2 EC points) The program uses a loop (for loop or while loop)
  • (2 EC points) The program modifies the data that it has read from the text file, and then saves the modified data back out to the text file before terminating
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#Code to change all 4 character words to #### and 5 character words to @@@@@ 6 character words to !!!!!!


def fun(x):
   
     
    
    ls=x.split(" ")
    
    z=[]
    
    st=""
    
  
    
    for i in ls:
        
        if len(i)==4:
            z.append("####")
            
        elif len(i)==5:
            z.append("@@@@@@")
        
        elif len(i)==6:
            z.append("!!!!!!")
        
        else:
            z.append(i)
            
    for i in z:
        
        st=st+i+" "
    
    return st
    
    
    
    
    
    
f = open("a.txt", "r")
x=f.readline()
f.close()



z=fun(x)


text_file = open("a.txt", "w")
n = text_file.write(z)
text_file.close()

print("The text has been changed and stored in a.txt")

Output:

a.txt before executing

Run Debug Share Save beauty Language Python 3 main.py a.txt Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiu

a.txt after executing

19 Run Debug Stop Share Save {} Beautify Language Python 3 main.py a.txt @@@@@@@@@@@@@@@@@@ sit #### consectetur adipiscing #

Console output:

53 54 print(The text has been changed and stored in a.txt) The text has been changed and stored in a.txt ... Program finish

1596046243176_image.png

Add a comment
Know the answer?
Add Answer to:
Give a problem statement that requires you to develop a Python program that meets the following...
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
  • Write a piece of Python code that meets the following requirements: Write a loop structure such...

    Write a piece of Python code that meets the following requirements: Write a loop structure such that: The range of control values is from 0 up to, but not including 11. The control variable is incremented by 1 for each iteration of the loop. For each iteration of the loop: Evaluate the control value When the control variable is equal to 1, 2, 3, 5, or 7, output a line of text that reads: "x is a prime number" where...

  • Create a working proof of concept of one of the following applications which meets all of...

    Create a working proof of concept of one of the following applications which meets all of the minimum requirements. The application may be written in any programming language(s). The application should be sent with the following: ● All of the source code required for building ● A completed binary of the application (if applicable) ● Any required database files (if applicable) Each application requires a README. Please ensure the README includes the following components: ● Which application you choose to...

  • Lab 1 Q1. Write a Python program with the following function building block. •All input values...

    Lab 1 Q1. Write a Python program with the following function building block. •All input values are to be taken fro m the user. •Ensure to check for possible error cases like mismatch of data type and input out of range, for every function.       Function 1: countVowels(sentence) – Function that returns the count of vowels in a sentence. Function 2: Sum of all even numbers between two numbers, identify number of parameters   Q2. Write a Python program that reads a...

  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • 1. You will develop a Python program to manage information about baseball players. The program will...

    1. You will develop a Python program to manage information about baseball players. The program will maintain the following information for each player in the data set: player’s name (string) team identifier (string) games played (integer) at bats (integer) runs scored (integer) hits (integer) doubles (integer) triples (integer) homeruns (integer) batting average (real) slugging percentage (real) The first nine items will be taken from a data file; the last two items will be computed by the program. The following formulas...

  • Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that...

    Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that uses at least two arrays, and has at least one loop that accesses the data in the arrays. As long as your program satisfies the requirements listed below, you are free to design and write any type of program that you care to. You are encouraged to be creative, and pick something that has meaning for you, because you'll have more fun. Feel free...

  • Please answer this python questions.Thank you! Question Two      Write a program that calculates the amount...

    Please answer this python questions.Thank you! Question Two      Write a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what the salary was for each day, and then show the total pay at the end...

  • In python, please code the following: Problem 4 Download the file ATLForecast.dat from canvas. You may...

    In python, please code the following: Problem 4 Download the file ATLForecast.dat from canvas. You may wish to open it to inspect the contents (then close the file to ensure no file locking implications). This file contains the minimum forecast temperature for the next 10 days in Atlanta (I'm waiting for the cool weather to start). Write a program that reads in the contents of this file (see example provided below, usinga function within numpy to read in this text...

  • Create a python program based on the following requirements the program should also have to have...

    Create a python program based on the following requirements the program should also have to have the following Base Class - Car (Make, Model, year) Sub Class - Gas (Make, Model, year, and gas per mile) Sub Class - Electric (Make, Model, year, and Full Battery charged per mile) 1. Add car 2. View car 3. Delete car 4. Exit program 1. The Car sell manager Application will need to store the car information for gas-powered car members and electric-powered...

  • Any little bit of information will be helpful. Thank you. Problem Statement You are to develop a program to read Mo...

    Any little bit of information will be helpful. Thank you. Problem Statement You are to develop a program to read MotoGP rider information from an input file. You will need a MotoGpRider class whose instances will be used to store the statistics for a MotoGP motorcycle racer. The Rider class will have attributes for last name, first name, racing number, nation, motorcycle make, world championship points, world championship position, and an array that stores the number of top finishes (number...

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