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...
Please write the following Python program. Also, show all output work. Computing the Fibonacci and Lucas...
Please write the following Python program. Also, show all output work. Computing the Fibonacci and Lucas Series¶ Goal:¶ The Fibonacci Series is a numeric series starting with the integers 0 and 1. In this series, the next integer is determined by summing the previous two. This gives us: 0, 1, 1, 2, 3, 5, 8, 13, ... We will write a function that computes this series – then generalize it. Step 1¶ Create a new module series.py in the session02...
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...
In python Write a program to implement RSA algorithm based on the public key. def encryptmessage():...
In python Write a program to implement RSA algorithm based on the public key. def encryptmessage(): def decryptmessage(): encryptmessage () decryptmessage () No in-built functions and third-party APIs will be allowed.
Create a preorder iterator for the class binarytree from the Python program below. class Binarytree: def...
Create a preorder iterator for the class binarytree from the Python program below. class Binarytree: def __init__(self, DataObject): self.data = DataObject self.parents = None self.left_child = None self.right_child = None @property def left_child(self): return self.__left_child @left_child.setter def left_child(self, node): self.__left_child = node if node is not None: node.parents = self @property def right_child(self): return self.__right_child @right_child.setter def right_child(self, node): self.__right_child = node if node is not None: node.parents = self def is_leafNode(self): if self.left_child is None and self.right_child is None:...
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; }
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT