Question

In: Computer Science

Write for Python IDLE 3.8.5 Write functions: i) One that prompts a user for 2 numbers....

Write for Python IDLE 3.8.5

Write functions:

i) One that prompts a user for 2 numbers.

ii) Adds the two numbers if they are even

iii) Multiplies the two numbers if they are odd

iv) Displays the appropriate output to the user

You are writing 4 functions and calling them to test functionality.

Solutions

Expert Solution

# Prompt on command to enter input
# returns both input
def promptTwoNumbers():
    x = int(input("Enter 1st Number : "))
    y = int(input("Enter 2nd Number : "))
    return [x,y]

# returns sum of two integers
def addTwoNumbers(x, y):
    return x+y

# returns multiplication of two integers
def multTwoNumbers(x, y):
    return x*y

# displays the result
def displayOutput(res):
    print(res)

# gets both inputs
print("Enter two Odd or two Even Numbers  ")
x, y = promptTwoNumbers()

# checks whether both even or both odd
if x%2 ==0 and y%2 ==0:
    ans = addTwoNumbers(x, y)
    res = "Sum of " + str(x) + " and " + str(y) + " = " + str(ans)
    displayOutput(res)
elif x%2 == 1 and y%2 == 1:
    ans = multTwoNumbers(x, y)
    res = "Multiplication of " + str(x) + " and " + str(y) + " = "+str(ans)
    displayOutput(res)
else:
    print("Please Enter Valid Input")

Output #1:

Output #2:


Related Solutions

run in python IDLE 3.9.0 i) One that prompts a user for 2 numbers. ii) Adds...
run in python IDLE 3.9.0 i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are even iii) Multiplies the two numbers if they are odd iv) Displays the appropriate output to the user You are writing 4 functions and calling them to test functionality.
Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers...
Write functions: i) One that prompts a user for 2 numbers. ii) Adds the two numbers if they are even iii) Multiplies the two numbers if they are odd iv) Displays the appropriate output to the user You are writing 4 functions and calling them to test functionality. RUN in IDLE
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments...
Write functions in Python IDLE that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both.
all python Question One [2 * 2.5] Write a program that prompts the user for two...
all python Question One [2 * 2.5] Write a program that prompts the user for two integers and then prints •The sum •The difference •The product •The average •The distance (absolute value of the difference) •The maximum (the larger of the two) •The minimum (the smaller of the two) Hint: Python defines max and min functions that accept a sequence of values, each separated with a comma. Write a program that prompts the user for a measurement in meters and...
Write a Python program using functions and mainline logic which prompts the user to enter a...
Write a Python program using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a file. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a minimum, the numbers should...
Write a Python program with correct indentation using functions and mainline logic which prompts the user...
Write a Python program with correct indentation using functions and mainline logic which prompts the user to enter a number, then generates that number of random integers and stores them in a list. It should then display the following data to back to the user: The list of integers The lowest number in the list The highest number in the list The total sum of all the numbers in the list The average number in the list At a minimum,...
Please use python and run in IDLE Question 1 Write functions that do the following: i)...
Please use python and run in IDLE Question 1 Write functions that do the following: i) A function that takes 2 arguments and adds them. The result returned is the sum of the parameters. ii) A function that takes 2 arguments and returns the difference, iii) A function that calls both functions in i) and ii) and prints the product of the values returned by both. Question 2 Write functions: i) One that prompts a user for 2 numbers. ii)...
JAVA 5- Write a program that prompts the user to enter two (2) numbers and compute...
JAVA 5- Write a program that prompts the user to enter two (2) numbers and compute the sum of the numbers between these two numbers (including the numbers entered). If the user Enters 2 and 6. The program will calculate the sum of the numbers: 2+3+4+5+6 and will display the result. Enter First number> 2 Enter second number> 6 The sum is 20
(PYTHON) Write aprogram that prompts user to enter three sides of a triangle....
(PYTHON) Write a program that prompts user to enter three sides of a triangle. The program should determine if the three sides can form a triangle. If the three sides can form a triangle, then determine the type of the triangle.There are three types of triangles: Equilateral triangle (all 3 sides are equal) Isosceles triangle (two sides are equal, the third side is of a different length) Scalene triangle (all 3 sides are of different lengths)   The program should...
In Python write a program that prompts the user for a file name, make sure the...
In Python write a program that prompts the user for a file name, make sure the file exists and if it does reads through the file, count the number of times each word appears and then output the word count in a sorted order from high to low. The program should: Display a message stating its goal Prompt the user to enter a file name Check that the file can be opened and if not ask the user to try...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT