Python
This is the code we are using:
def main ():
video_file = open ( 'video_times.txt')
list = []
for line in video_file:
run_time = float(line)
list.append (run_time)
print ('Video #', ':', run_time)
print(list)
sum = 0
for i in range(len(list)):
sum = sum + list[i]
video_file.close
main ( )
The following text is read from the video_times.txt file:
Video # 1 : 10.0
Video # 2 : 24.5
Video # 3 : 12.2
Video # 4 : 14.6
Video # 5 : 20.4
Video # 6 : 22.5
Video # 7 : 19.3
Video # 8 : 18.6
Video # 9 : 17.5
Video # 10 : 14.8
Video # 11 : 12.2
How do I change the code so that the total running time and average running time is displayed at the end of this output? We need to sum the times and figure out the average.
The total running time is 186.6 seconds
The average running time is 16.963636363636365
#Python program
def main ():
video_file = open ( 'video_times.txt')
list = []
count = 0
sum=0
for line in video_file:
run_time = float(line)
list.append (run_time)
for run_time in list:
count+=1
print ('Video #',count, ':', run_time)
sum = sum + run_time
print('The total running time is ',sum,' seconds')
print('The average running time is ',sum/count)
video_file.close
main ( )
#Screenshot
![File Edit Format Run Options Window Help def main (): video_file = open(video times.txt) list = [] count = 0 sum=0 for line](http://img.homeworklib.com/questions/54e93770-7a61-11eb-879e-ef0d039b10fb.png?x-oss-process=image/resize,w_560)
Python This is the code we are using: def main (): video_file = open ( 'video_times.txt')...
I am trying to finish the code below. class DVD: def __init__(self, title, dvd_type, cost): self.title = title self.dvd_type = dvd_type self.cost = cost def setTitle(self, netTitle): self.title = newTitle def getTitle(self): return self.title def getType(self): return self.dvd_type def getCost(self): return self.cost def setCost(self, newCost): self.cost = newCost def setType(self, newdvd_Type): validTypes = ['Game', 'Word', 'Compiler', 'Spreadsheet', 'dBase', 'Presentation'] while True: self.dvd_type = input( 'Please enter the valid type: (Game, Word, Compiler, Spreadsheet, dBase, Presentation)') if self.dvd_type() not in validTypes:...
Using a sort method and my previous code (put inside of addHours method if possible), how would I get the list of each employee's total hours to display in order of least amount of hours to greatest. An explanation for each step would also be great. import random #Create function addHours def addHours(lst): #Display added hours of employees print("\nEmployee# Weekly Hours") print("----------------------------") print(" 1 ",sum(lst[0])) print(" 2 ",sum(lst[1])) print(" 3 ",sum(lst[2])) #Create main function def main(): #Create first empty list...
I dont know how to get this code working??? this is my code: # read_running_times.py # Chapter 6.2 Page 258 def main(): # Open the video_times.txt file for reading. video_file = open('video_times.txt', 'r') # Initialize an accumulator to 0.0 total = 0.0 # Initialize a variable to keep count of the videos. count = 0 print('Here are the running times for each video:') # Get the values from the file and total them. for line in video_file: # Error 1:...
Consider the following Python program, where x is assumed to be a list of integers. def mystery_func(x): n = len(x) for i in range(n - 1): for j in range(i + 1, n): if x[j] - x[i] < j - i: return False return True 3a. In plain English, describe what it accomplishes (i.e., the relationship between input and output, not how the code works). 3b. Analyze the running time and express it with big O. 3c. Rewrite this function...
python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try: f = open("shopping2.txt","r") for line in f: sl.append(line.strip()) f.close() except: pass def mainScreen(): os.system('cls') # for linux 'clear' print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print(" SHOPPING LIST ") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("\n\nYour list contains",len(sl),"items.\n") print("Please choose from the following options:\n") print("(a)dd to the list") print("(d)elete from the list") print("(v)iew the...
Python Error: Writing a program to complete the following: Prompt the user for the name of an input file. Open that file for input. (reading) Read the file using a "for line in a file" loop For each line, o print the line and compute and print the average word length for that line. Close the input file Sample output: MY CODE IS WRONG AND NEED HELP CORRECTING IT!!! ------------------------------------------------------------------------------------------------------------------------ DESIRED OUTPUT: Enter input file name: Seasons.txt Thirty days hath September...
THIS IS THE CODE I AM TRYING TO RUN code # def main(): #Reading a as an integer a = int(input("Enter value for a: ")) #reading b as an interger b = int(input("Enter value for b: ")) #reading n as an integer n = int(input("Enter value for n: ")) # displaying if a and b are congruent modulo n, this is True if a and b #both returns same remainder when divided by n if a % n == b...
Need help writing this code in python.
This what I have so far.
def display_menu():
print("======================================================================")
print(" Baseball Team Manager")
print("MENU OPTIONS")
print("1 - Calculate batting average")
print("2 - Exit program")
print("=====================================================================")
def convert_bat():
option = int(input("Menu option: "))
while option!=2:
if option ==1:
print("Calculate batting average...")
num_at_bats = int(input("Enter official number of at bats:
"))
num_hits = int(input("Enter number of hits: "))
average = num_hits/num_at_bats
print("batting average: ", average)
elif option !=1 and option !=2:
print("Not a valid...
Please can I have a UML Class diagram for the Python program below: def main(): print() print("Welcome to Caesar Encryption and Viginere Decryption Cipher") print() print("Please select an option") option = "c" while option == "c": hello = input('Choose Caesar Cipher encrypt 1:\n' 'Choose Viginere Cipher Decrypt 2:\n') message = input('Enter a message: ') password = input('Enter a password: ') if hello == '1': viginere_cipher(message, password) elif hello == '2': viginere_cipher_decrypt(message, password) print() print("Choose an option") option = input('Enter c...
Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX): message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user num = int(input(message)) while num < MINN or num > MAXX: print("Invalid choice!") num = int(input(message)) #return result return num #counts dupes def twoInARow(numbers): ans = "No duplicates next to each...