Question

In: Computer Science

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

Solutions

Expert Solution

#to user input
def get_input():
    a= int(input("Enter first  number"))
    b= int(input("Enter second  number"))
    return a,b

#adding two numbers
def add(a,b):
    return a+b

#Multiply two numbers
def multiply(a,b):
    return a*b
    
#display result
def display(res):
    print("result is",res)

#testing functionality
#call get_input
input1,input2= get_input()
if(input1%2==0 and input2%2==0):
    #if both are even then add
    output=add(input1,input2)
    #display result
    display(output)
elif (input1%2==1 and input2%2==1):
    #if both are odd then product
    output=multiply(input1,input2)
    #display result
    display(output)
else:
    #assuming if either of them is odd and other is even then it is invalid
    print("wrong input..")
    

    

in the programme I have considered if both are even then add ,if both are odd then product for other cases invalid input

ts..


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 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.
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
C++ Program: Write a program that prompts the user for two numbers and stores them in...
C++ Program: Write a program that prompts the user for two numbers and stores them in signed integers. The program should then add those two numbers together and store the result in a signed integer and display the result. Your program should then multiply them by each other and store the result in another integer and display the result. Then do the same but with dividing the first number by the second. Display an error message to the screen if...
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 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
Using Java Prime numbers. Write a program that prompts the user for an integer and then...
Using Java Prime numbers. Write a program that prompts the user for an integer and then prints out all prime numbers up to that integer. For example, when the user enters 20, the program should print 2 3 5 7 11 13 17 19 Recall that a number is a prime number if it is not divisible by any number except 1 and itself. Use a class PrimeGenerator with methods nextPrime and isPrime. Supply a class PrimePrinter whose main method...
You will write a program that prompts the user to enter a 7-digit phone numbers, and...
You will write a program that prompts the user to enter a 7-digit phone numbers, and finds the 3- and 4-letter words that map to the phone number, according to the restrictions outlined earlier. A sample run: unixlab% java MapNumbers Enter name of dictionary file: words10683 Enter a test word (3 letters): cat Test word maps to 228 Enter telephone number (7 digits, no 0's or 1's, negative to quit): 2282273 Options for first 3 digits: act cat bat Options...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
You are required to write an interactive JS program that prompts the user for three numbers...
You are required to write an interactive JS program that prompts the user for three numbers and then finds the sum, average, smallest, and the largest value of the numbers and prints the results labeling properly.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT