Concept explainers
Python
Write a
Ex: If the input is:
input1.txt ammoniated millennium
and the contents of input1.txt are:
aspiration classified federation graduation millennium philosophy quadratics transcript wilderness zoologists
the output is:
aspiration classified federation graduation millennium
my code is not working im getting an indentation error
#input filename
filename = open(input())
#input lower bound
str1 = input()
#input upper bound
str2 = input()
#read lines from file
l = filename.readlines()
#heading message
print()
#for each loop to read line one by one
for i in l:
#strip line
i = i.strip()
#check all line between lower and upper bound
if str1 <= i <= str2:
#print line
print(i)
#close file
filename.close()
Trending nowThis is a popular solution!
Step by stepSolved in 5 steps with 3 images
- Python please: Given the input file input1.csv write a program that first reads in the name of the input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words in a sorted list. The contents of the input1.csv are: hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy Example: If the input is input1.csv the output is: ['Cat', 'Hello', 'boy', 'boy', 'cat', 'cat', 'dog', 'dog', 'hello', 'hey', 'hey', 'man', 'man', 'woman'] Note: There is a newline at the end of the output.arrow_forwardThe objective of this problem is to show that you can write a program that reads a text file and uses string methods to manipulate the text. File cart.txt contains shopping cart type data from golfsmith.com representing the gifts you have purchased for your dad for this past Fathers Day. Good for you. You have been very generous! The first item in each row of the file is the part number, the second the quantity, the third the price and the fourth the description. Your program will read the file line by line and compute the total cost of all of the items in the list. You will then display a message that looks like this, assuming the cost of each item adds up to 168.42: Here's what your output should look like: The total price for the awesome Fathers Day gifts you bought is $168.42. The shopping cart can be found here: cart.txt. Right click on the link and save the file to the folder where you have your Python files.arrow_forwardWrite a python program that prompts the user for their favorite basketball team. It should be able to read the list of teams provided below in a file called favorite_teams.txt and check if their team is in that file. Teams in the file:JazzBullsMavericksSpursIf the team is in the file let the user know that their team is in the list of favorites. If the team is not in the file, add the team to the end of the file. Also, let the user know that their team will be added to the file.Sample Run in File:What is your favorite NBA team? Jazz [Enter]Your team Jazz is in the listFile before and after run: JazzBullsMavericksSpurs Sample Run not in File:What is your favorite NBA team? Pelicans [Enter]Your team Pelicans is not in the list. It will be added.File before run: JazzBullsMavericksSpursFile after run:JazzBullsMavericksSpursPelicansarrow_forward
- Modify task2.c so it will read from standard input and translate the contents just like the filter tr Modify this program so it work like trHint:if you run your program:./task2 abc ABCthen argv[1] is string "abc" argv[2] is the string "ABC" */ #include <stdio.h>#include <unistd.h>#include <string.h> int main(int argc, char *argv[]){ char c; while(1){ int r = read(0,&c,1); if(r==0) break; write(1,&c, 1); } return 0;}arrow_forwardJava Your program must read a file called personin.txt. Each line of the file will be a person's name, the time they arrived at the professor's office, and the amount of time they want to meet with the professor. These entries will be sorted by the time the person arrived. Your program must then print out a schedule for the day, printing each person's arrival, and printing when each person goes in to meet with the professor. You need to print the events in order of the time they happen. In other words, your output will be sorted by the arrival times and the times the person goes into the professor's office. In your output you need to print out a schedule. In the schedule, new students go to the end of the line. Whenever the professor is free, the professor will either meet with the first person in line, or meet with the first person in line if nobody is waiting. Assume no two people arrive at the same time. You should solve this problem using a stack and a queue. You can only…arrow_forwardSuggest a suitable life cycle model for a software project which your organization has undertaken on behalf of certain customer who is unsure of his requirements and is likely to change his requirement frequently. Give the reasons behind your answer.arrow_forward
- The next part of the program reads the file one line at a time and adds the scores, as a floating point numbers, to the list scores. scores = [] # empty list of scores for line in infile: line = line.strip() print (scores) # get score #convert to float # add to list of scores In the space below, complete the program fragment so that it prints the list of floating point scores as follows: [98.5, 97.4, 99.1, 97.2]arrow_forwardIn pythonarrow_forwardPython write a program in python that plays the game of Hangman. When the user plays Hangman, the computer first selects a secret word at random from a list built into the program. The program then prints out a row of dashes asks the user to guess a letter. If the user guesses a letter that is in the word, the word is redisplayed with all instances of that letter shown in the correct positions, along with any letters correctly guessed on previous turns. If the letter does not appear in the word, the user is charged with an incorrect guess. The user keeps guessing letters until either: * the user has correctly guessed all the letters in the word or * the user has made eight incorrect guesses. one for each letter in the secret word and Hangman comes from the fact that incorrect guesses are recorded by drawing an evolving picture of the user being hanged at a scaffold. For each incorrect guess, a new part of a stick-figure body the head, then the body, then each arm, each leg, and finally…arrow_forward
- please help on this python problem, produce new codarrow_forwardreads in a file of student academic credit data. Each line of the input filewill contain the student name (a single String with no spaces), the number of semester hours earned (an integer),the total quality points earned (a double).Here is the students.dat data file:students.dat Smith 27 83.7Jones 21 28.35Walker 96 182.4Doe 60 150Wood 100 400Street 33 57.4Taylor 83 190Davis 110 198Smart 75 292.5Bird 84 168Summers 52 83.2 My question is how can I create the <<students.dat>> I already have the code but I just need help to create the students.datarrow_forwardGiven a text file containing the availability of food items, write a program that reads the information from the text file and outputs the available food items. The program first reads the name of the text file from the user. The program then reads the text file, stores the information into four separate lists, and outputs the available food items in the following format: name (category) - description Assume the text file contains the category, name, description, and availability of at least one food item, separated by a tab character ('\t'). Ex: If the input of the program is: food.txt and the contents of food.txt are: Classic ham sandwich Available sandwich Chicken salad sandwich Not available Classic cheeseburger Cheeseburger Not available Salads Water 16oz bottled water Available Caesar salad Chunks of romaine heart lettuce dressed with lemon juice Available Salads Asian salad Mixed greens with ginger dressing, sprinkled with sesame Not available Beverages Beverages Mexican food…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education