Question

In: Computer Science

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.

Solutions

Expert Solution

Program Code Screenshot:

Sample Output:

The screenshots are attached below for reference.

Please follow them for proper indentation and output.

Please upvote my answer. Thank you.

Program code to copy:

def read():
print("Enter two numbers:")
l=list(map(int,input().split()))#read two numbers and return them
return l[0],l[1]

def add(n1,n2):
if n1%2==0 and n2%2==0:#add numbers if they are even
return n1+n2
else:
return None

def multiply(n1,n2):
if n1%2!=0 and n2%2!=0:#multiply two numbers if they are odd
return n1*n2
else:
return None

def display(a,m,n1,n2):
print("The numbers are:",n1," ",n2)#print the numbers
if a is None:
print("The addition is not possible")#print message when numbers are not even
else:
print("The addition is :",a)#print appropriate results
if m is None:
print("The multiplication is not possible")#print message when numbers are not odd
else:
print("The multiplication is :",m)

n1,n2=read()#call methods
a=add(n1,n2)
m=multiply(n1,n2)
display(a,m,n1,n2)


Related Solutions

Python 2. Please ensure you run the tests in idle Write a function orderPizza that allows...
Python 2. Please ensure you run the tests in idle Write a function orderPizza that allows the user input to build a pizza. It then prints a thank you message, the cost of the pizza and then returns the Pizza that was built. >>> orderPizza() Welcome to Python Pizza! What size pizza would you like (S,M,L): M Type topping to add (or Enter to quit): mushroom Type topping to add (or Enter to quit): onion Type topping to add (or...
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
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.
(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...
create a Python script that prompts the user for a title, description, and filename of your...
create a Python script that prompts the user for a title, description, and filename of your Python program and add the following to the bottom of the existing homepage: Add the post title with an emphasis Add the post description beneath the post title Create a hyperlink to the Python file using the filename input Create another hyperlink to the page you will create in the Web Showcase assignment
python.Write a python program that prompts the user to enter the year and first day of...
python.Write a python program that prompts the user to enter the year and first day of the year, and displays the first day of each month in the year. For example, if the user entered the year 2020 and 3 for Wednesday, January 1, 2020, your program should display the following output: January 1, 2020 is Wednesday February 1, 2020 is Saturday …… December 1, 2020 is Tuesday
Write a test program that prompts the user to enter a sequence of numbers ending with...
Write a test program that prompts the user to enter a sequence of numbers ending with 0, and invokes this method to return the largest number in the input. Use inheritance and polymorphism approach. in java please
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the...
(JAVA) Implementing a Program Design a program that prompts the user for twenty numbers. If the number is positive, then add the number to the current sum. If the number is negative, then subtract the sum by one. Implement just the main method. Assume that all libraries are imported, and class has been declared.
Python A program which prompts the user to enter an number which is a integer n...
Python A program which prompts the user to enter an number which is a integer n and creates a tuple where the values are all numbers between 1 and n (both inclusive). Note: you can assume that the integer will always be > 1. Input Result 3 Enter an integer: 3 (1, 2, 3)
Write a Flask app in which a Python script prompts the user to enter a string...
Write a Flask app in which a Python script prompts the user to enter a string and then that string, as entered, gets displayed on an otherwise blank HTML file, called output.html. Show the Python/Flask code and the html code of the output.html file, one below the other as part of your answer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT