Question

In: Computer Science

In Python Find the errors, debug the program, and then execute to show the output. def...

In Python

Find the errors, debug the program, and then execute to show the output.

def main():
    Calories1 = input( "How many calories are in the first food?")
    Calories2 = input( "How many calories are in the first food?")
    showCalories(calories1, calories2)
  
def showCalories():
    print('The total calories you ate today', format(calories1 + calories2,'.2f'))

Solutions

Expert Solution

Program:

#definition of main()
def main():
calories1 = float(input("How many calories are in the first food? "))
calories2 = float(input("How many calories are in the second food? "))
#calling showCalories() with 2 arguments
showCalories(calories1, calories2)
  
def showCalories(calories1, calories2):
#printing the total calories  
print("The total calories you ate today: %.2f" %(calories1+calories2))


#calling main()
main()

Program screenshot:

Output:


Related Solutions

Reminder, remember to code, evaluate, save, execute (run), and check the Python program for possible errors....
Reminder, remember to code, evaluate, save, execute (run), and check the Python program for possible errors. Remember to create the sales.txt file with the following data (1000, 2000, 3000, 4000, 5000). Tip, the sales.txt file must be in the same directory as the read_sales_text_file.py Python program. def main(): sales_file = open('sales.txt', 'r') for line in sales_file: amount = float(line) print('$', format(amount, '.2f')) sales_file.close() main() Output after you successfully run your code: $ 1000.00 $ 2000.00 $ 3000.00 $ 4000.00 $...
Please fix all the errors in this Python program. import math def solve(a, b, c): """...
Please fix all the errors in this Python program. import math def solve(a, b, c): """ Calculate solution to quadratic equation and return @param coefficients a,b,class @return either 2 roots, 1 root, or None """ #@TODO - Fix this code to handle special cases d = b ** 2 - 4 * a * c disc = math.sqrt(d) root1 = (-b + disc) / (2 * a) root2 = (-b - disc) / (2 * a) return root1, root2 if...
Try to debug it! ######################################## ##def rev_list_buggy(L): ## """ ## input: L, a list ## Modifies...
Try to debug it! ######################################## ##def rev_list_buggy(L): ## """ ## input: L, a list ## Modifies L such that its elements are in reverse order ## returns: nothing ## """ ## for i in range(len(L)): ## j = len(L) - i ## L[i] = temp ## L[i] = L[j] ## L[j] = L[i] # ## FIXES: -------------------------- ## temp unknown ## list index out of range -> sub 1 to j ## get same list back -> iterate only over...
Try to debug it! (fixes needed are explained below) ######################################## ##def primes_list_buggy(n): ## """ ## input:...
Try to debug it! (fixes needed are explained below) ######################################## ##def primes_list_buggy(n): ## """ ## input: n an integer > 1 ## returns: list of all the primes up to and including n ## """ ## # initialize primes list ## if i == 2: ## primes.append(2) ## # go through each elem of primes list ## for i in range(len(primes)): ## # go through each of 2...n ## for j in range(len(n)): ## # check if not divisible by...
PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def...
PYTHON PROBLEM: TASKED TO FIND THE FLAW WITH THE FOLLOWING CODE: from itertools import count def take_e(n, gen):     return [elem for (i, elem) in enumerate(gen) if i < n] def take_zc(n, gen):     return [elem for (i, elem) in zip(count(), gen) if i < n] FIBONACCI UNBOUNDED: def fibonacci_unbounded():     """     Unbounded Fibonacci numbers generator     """     (a, b) = (0, 1)     while True:         # return a         yield a         (a, b) = (b, a + b) SUPPOSED TO RUN THIS TO ASSIST WITH...
What's wrong with my Python code. We have to find the regularexpression in Python My output...
What's wrong with my Python code. We have to find the regularexpression in Python My output should look like this My IP address 128. 0. 0. 1 My IP address 53. 20. 62. 201 My code ipAddresses = [] ipRegEx = re.compile(r"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")    result = myRegEx.find all(Search Text)    def Regular_expression(ipAddresses)       for i in ipAddresses:          print(i) ipSearchResult = ipRegEx.search(line)    if ipSearchResult != None and ipSearchResult.group() not in ipAddresses:       ipAddresses.append(ipSearchResult.group()) we have to use loop too.
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;...
Analyze following program and Find Syntax errors. #include<iostream> int show(int x) int main() {     int A,B;       char B=10; cout<<”Enter Value of A”; cin<<A; show(A) show(50)          }       cin.get(); } int show(int x); { cout<<”Value is =” <<X cout<<endl; }
In this python script find any bugs and errors which would cause the code to crash....
In this python script find any bugs and errors which would cause the code to crash. The code must be re-written correctly. After debugging make a separate list of all the errors you found in the script. contacts_list=[] # global variable, list of contacts_list, one string per contact def pause()     """ pauses program e.g. to view data or message """     input("press enter to continue") def load():     """ populate list with data """          contacts_list.append(('Milo ', '063847489373'))...
Python Please debug each python block. Do not change the algorithm. You can add statements or...
Python Please debug each python block. Do not change the algorithm. You can add statements or you can modify existing python statements. #2) The below code prints all numbers from 5 to 20. Modify the below while loop to print odd numbers from 5 to 21, # including 21. Correct syntax errors as well. i = 5 while(i<21): print(i) i = i+1
fix this code in python and show me the output. do not change the code import...
fix this code in python and show me the output. do not change the code import random #variables and constants MAX_ROLLS = 5 MAX_DICE_VAL = 6 #declare a list of roll types ROLLS_TYPES = [ "Junk" , "Pair" , "3 of a kind" , "5 of a kind" ] #set this to the value MAX_ROLLS pdice = [0,0,0,0,0] cdice = [0,0,0,0,0] #set this to the value MAX_DICE_VAL pdice = [0,0,0,0,0,0] cdice = [0,0,0,0,0,0] #INPUT - get the dice rolls i...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT