Question

In: Computer Science

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) 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

PYTHON CODE

1)

def add_num(a,b):#function for addition
sum=a+b
return sum; #return value
  
def diff(a,b):#function for difference
diff=a-b
return diff
def call(a,b): # function for Product of the values returned by both
e=add_num(a,b)
f=diff(a,b)
pro=e*f
print("Product of the values returned by both =",pro)


a=25 #variable declaration
b=5
call(a,b) #function call

OUTPUT

2)


def add_num(a,b):#function for addition if number is even
sum=0
if a%2==0 and b%2==0:
sum=a+b
return sum #return value
  
def accept():#function to accept values
print("Enter two number : ")
a =int(input())
b = int(input())
s=add_num(a,b) #function call
p=Product(a,b) #function call
display(s,p)
  
def Product(a,b): # function for finding product if number is odd
pro=0
if a%2!=0 and b%2!=0:
pro=a*b
return pro #return value
def display(s,p): #function for display
if s!=0 :
print("The sum is = ",s)
elif p!=0 :
print("The Product is = ",p)
else:
print("one numberis odd and other number is even")


accept() #function call

OUTPUT


Related Solutions

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.
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.
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...
Write functions that do the following in Python: i) A function that takes 2 arguments and...
Write functions that do the following in Python: 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.
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
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.
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the...
In IDLE - Python 3, do the following: 1. Create File --> New 2. Enter the code below in the new file (you may omit the comments, I included them for explanation #Python Code Begin x = int(input("Enter a number: ")) y = int(input("Enter another number: ")) print ("Values before", "x:", x, "y:", y) #add code to swap variables here #you may not use Python libraries or built in swap functions #you must use only the operators you have learned...
Write this in java please. I use Eclipse Write the following two functions. main doesnt need...
Write this in java please. I use Eclipse Write the following two functions. main doesnt need to be filled up. Function 1: Write a function called howMany that takes two arguments: an array of integers called arr, and an integer called iTarget. The function should return an integer result. Inside the function write a loop to go through the array and count the number of elements in the array that have the same value as iTarget. At the end it...
Do it in python please Write a program using functions and mainline logic which prompts the...
Do it in python please Write a 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 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...
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS....
PLEASE NOTE:1)-DO NOT USE FUNCTIONS USE ONLY DO WHILE LOOP.                          2)DO NOT USE IN-BUILT FUNCTIONS.                          3)Use of string and char is not allowed.             Write a program in c laungage that prints a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range1 through 256.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT