Question

# Find the error in the following program. def main():     # Get a value from...

# Find the error in the following program.
def main():
    # Get a value from the user.
    value = input("Enter a value.")
    # Get 10 percent of the value.
    ten_percent(value)
    # Display 10 percent of the value.
    print("10 percent of ", value, " is ", result)

# The ten_percent function returns 10 percent
# of the argument passed to the function.
def ten_percent(num):
    return num * 0.1

main()

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Find the error in the following program.
def main():
    # Get a value from the user.
    value = float(input("Enter a value."))  # Error 1. Read input as a number
    # Get 10 percent of the value.
    result = ten_percent(value) # Error 2. assign result to a variable
    # Display 10 percent of the value.
    print("10 percent of ", value, " is ", result)


# The ten_percent function returns 10 percent
# of the argument passed to the function.
def ten_percent(num):
    return num * 0.1


main()

Add a comment
Know the answer?
Add Answer to:
# Find the error in the following program. def main():     # Get a value from...
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
  • in python 3 1. A program contains the following function definition: def cube(num): return num *...

    in python 3 1. A program contains the following function definition: def cube(num): return num * num * num Write a statement that passes the value 4 to this function and assign its return value to the variable result. 2. Write a function named get_first_name that asks the user to enter his or her first name and returns it.

  • THIS CODE IS IN PYTHON #This program calls a function from the main function def getInput():...

    THIS CODE IS IN PYTHON #This program calls a function from the main function def getInput(): ''' This function gets the rate and the hours to calculate the pay ''' userIn = float(input("Enter the rate: ")) print(userIn) inputHours = float(input("Enter the hours: ")) print(inputHours) def main(): getInput() main() YOU NEED TWO FUNCTIONS : main() function get_inputs function

  • ##8. A program contains the following function definition: ##def cube(num): ##return num * num * num...

    ##8. A program contains the following function definition: ##def cube(num): ##return num * num * num ##Write a statement that passes the value 4 to this function and assigns its return value ##to the variable result. ##9. Write a function named times_ten that accepts a number as an argument. When the ##function is called, it should return the value of its argument multiplied times 10. ##10. Write a function named is_valid_length that accepts a string and an integer as ##arguments....

  • STAGE 1 In Stage #2 here are the requirements: • Keep the following requirements from Stage...

    STAGE 1 In Stage #2 here are the requirements: • Keep the following requirements from Stage #1 o Write code that calls a function named printMenu() • The printMenu() function will: • print the menu below . ask the user to input a value between 1 an 12 · return an integer value to your main program. • Within the printMenu() function: o I STRONGLY SUGGEST THAT YOU DO THESE ONE AT A TIME - get the loop working before...

  • In python using a def main() function, Write a function that will print a hello message,...

    In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...

  • Implement a Python function that prints integers from a to b. The main part of the...

    Implement a Python function that prints integers from a to b. The main part of the program should ask the user to input a and b and call the function. # Display integers a, a+1, a+2, ..., b def display(a,b): ## complete your work here ## return a = int(input("Please prvide a value for a: ")) b = int(input("Please prvide a value for b: ")) display(a,b)

  • This is a python question. Start with this program, import json from urllib import request def...

    This is a python question. Start with this program, import json from urllib import request def main(): to_continue = 'Yes' while to_continue == 'yes' or to_continue == 'Yes': currency_code = input("Enter currency code: ").upper() dollars = int(input("Enter number of dollar you want to convert: ")) # calling the exchange_rates function data = get_exchange_rates() if currency_code in data["rates"].keys(): currency = data["rates"][currency_code] # printing the the currency value by multiplying the dollars amount. print("The value is:", str(currency * dollars)) else: print("Error: the...

  • Number 1) Which of the following statements imports a module into the default namespace? a. from...

    Number 1) Which of the following statements imports a module into the default namespace? a. from temperature import * b. import temperature as t c. import temperature as temp d. import temperature Number 2) Which of the following statements imports a module into the global namespace? a.from temperature import *   b. import temperature as temp c. import temperature as global d. import temperature Number 3) Code Example 4-2 def get_volume(width, height, length=2):     volume = width * height * length...

  • 4. Write a function that returns a value to the main program illustrated below. In the...

    4. Write a function that returns a value to the main program illustrated below. In the function, the variable passed by the main program needs to be evaluated using a switch statement. The value returned is determined by the case that it matches. (10 points) If value is: return 10 return 20 3 return 30 Anything else, return 0 Main program: #include <iostream> using namespace std; int findValue (int); int main) { Int numb, retvalue cout << "In Enter a...

  • Write a C++ program that computes the following series: sum = 1/firstPrime + 2/secondPrime+…..+1/nthPrime Your program...

    Write a C++ program that computes the following series: sum = 1/firstPrime + 2/secondPrime+…..+1/nthPrime Your program should prompt the user to enter a number n. The program will compute and display sum based on the series defined above. firstPrime: is 2 secondPrime: the first prime number after 2 thirdPrime: the third prime number …. nth prime: the nth prime number Your program must be organized as follows: int main() { //prompt the user to enter n //read n from the...

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