Question
python question
2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the fo
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if anything is required. Please follow the indentation as shown in the code screenshot.

Code screenshot:

3 10 input_filename = input(Enter the name of the input file: ) Wopening the input file to read the contents 4. try:#try ca

ILIUL.UPPellum ILY) elseprint(stnum. Hif avg_quiz i5.9057 WNobovou AwNoooo va #code to find the student is pass or fail for

Sample input: students.txt

1111 85 65 89 90
2222 55 45 67 85
3333 45 55 67 85
4444 45 55 47 85
5555 55 45 47 85
6666 45 55 85 47
7777 55 45 85 47
8888 45 46 47 48
9999 45 45 67 67
0000 76 89

Sample output:

Share Save {} Beautify Run Debug Stop students.txt results.txt main.py 1 111 2 2222 3 3333 4 5555 5 7777

Copyable code:


input_filename = input("Enter the name of the input file: ")
#opening the input file to read the contents
try:#try catch for the file reading
f1 = open(input_filename,'r')
except:
print("The file is not exist !")
else:
output_filename = input("Enter the name of the output file: ")
f2 = open(output_filename,"w") #output file to write the contents
student=[]
avg_quiz=[]
avg_ass=[]
mid_term=[]
final=[]
for line in f1: #reading contents of file
line=line.strip()#to remove leading spaces
l=line.split()
if len(l) < 5:
print("Student Information is missing for student ID: "+str(l[0])) #if any student Information is missing
else:
student.append(l[0]) #else storing the marks into the list
avg_quiz.append(int(l[1]))
avg_ass.append(int(l[2]))
mid_term.append(int(l[3]))
final.append(int(l[4]))
#code to find the student is pass or fail
for i in range(len(student)):
if(avg_quiz[i]>=50 ): #if avg_quiz is greater than 50 percent then mid_term or final is greater than 50
if(mid_term[i]>=50 or final[i]>=50):
print("stnum: "+str(student[i])+" result: pass")
f2.write(student[i]+"\n")
else:
print("stnum: "+str(student[i])+" result: fail")#else fail
elif (avg_ass[i]>=50):#if avg_quiz is greater than 50 percent then mid_term and final is greater than 50
if(mid_term[i]>=50 and final[i]>=50):
print("stnum: "+str(student[i])+" result: pass")
f2.write(student[i]+"\n")
else:
print("stnum: "+str(student[i])+" result: fail")#else fail
else:
print("stnum: "+str(student[i])+" result: fail")#else fail
  

Add a comment
Know the answer?
Add Answer to:
python question 2. In a file called passfail.py, write a Python program to solve 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
  • 2. In a file called passfail.py, write a Python program to solve the following problem: Given...

    2. In a file called passfail.py, write a Python program to solve the following problem: Given a file students.txt with the following information for a stu dent: student number, average quiz mark, average assignment mark, midterm exam mark, and final exam mark (where each mark is recorded out of 100), de termine if the student has passed or failed based on the following information A student will pass the course if they have a passing mark (50% or higher) for...

  • 3. Design and implement a class called ClassStats, in a file called stats.py, that includes: •...

    3. Design and implement a class called ClassStats, in a file called stats.py, that includes: • private attributes for a student number and status (pass or fail), • private class variables to keep track of the total number of students with status pass and the total number of students with status fail, • a constructor with default values (empty strings) for all instance variables, • an accessor method for each instance variable and also for the class vari- ables, •...

  • Write a Python program (question2.py) that reads from a file called “input.txt” numbers in [1,39] separated...

    Write a Python program (question2.py) that reads from a file called “input.txt” numbers in [1,39] separated in by commas. The numbers are in [1-99]. The program will then convert each number to a possible Roman Numeral equivalent, and print it on the screen. Remember, I is 1, V is 5, X is 10 For example, if the input is: 23, 11 the output is: XXIII, XI. ROMAN NUMERALS CHART 1 TO 100 69 LXIX 11 2 11 3 III 4...

  • 1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat,...

    1. Write a Python program, in a file called concat_strings.py, that includes the following functions: orderedConcat, a recursive function that takes two alphabetically-ordered strings and merges them, leaving the letters in alphabetical order. Note that the strings may be different lengths. a main method that inputs two ordered strings and calls the orderedConcat method to return a resulting merged, ordered string. Your main method should print the two input strings and the result. Note: You may not use any of...

  • Write a C++ program that computes student grades for an assignment as a percentage given each...

    Write a C++ program that computes student grades for an assignment as a percentage given each student's score and the total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath header file and displayed as a percentage. You must also display the floating-point result up to 5 decimal places. You must use at least 2 functions: one to print the last name of the student and another function to...

  • WRITE SQL QUERY THAT DOES THE FOLLOWING Q3| Find the customer's name and branch names of...

    WRITE SQL QUERY THAT DOES THE FOLLOWING Q3| Find the customer's name and branch names of all customers who do have accounts but not a loan in the bank. And find those customers who do have loan but not have an account in the bank. GIVEN DATABASE TABLES 2 Account table Branch table Customer table Loan table BNAME 3 A# CNAME BNAME BAL BNAME ASSETS BCITY CNAME STREET CCITY CNAME AMT 1234 Baba 2222 Rahimi Sauthdale Ridgedale 150eee Minnetonka Minnetonka...

  • Use of search structures! how can i make this program in python? Learning Objectives: You should...

    Use of search structures! how can i make this program in python? Learning Objectives: You should consider and program an example of using search structures where you will evaluate search trees against hash tables. Given the three text files under containing the following: - A list of students (classes Student in the distributed code) - A list of marks obtained by the students (classes Exam results in the distributed code) - A list of topics (classes Subject in the distributed...

  • Write, test and document a Python program, in a file called MarsCoins.py, to solve the following problem Marvin from Ma...

    Write, test and document a Python program, in a file called MarsCoins.py, to solve the following problem Marvin from Mars has a jar full of martian currency (Maruvians, Caruvians, Taruvians and Paruvians). The breakdown of the currency units on Mars is as follows: The single smallest unit of currency is a Paruvian 6 Paruvians 1 Taruvian 12 Paruvians 1 Caruvian 24 Paruvians1 Maruvian Marvin wants to share his money with his friends but he doesn.t want to carry around all...

  • PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything...

    PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...

  • Write a Java program, In this project, you are going to build a max-heap using array...

    Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...

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
ADVERTISEMENT