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.
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...
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...
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...
Do it in python please! also please use this template please I have provided and below...
Do it in python please! also please use this template please I have provided and below is the activity def main(): # import the module random try: # asking the user to enter a number between 1 and 100 #loop time while if elif #for loop # generates that number of random integers and stores them in a list for x in # computations # displays the results on the screen # call try_Again to give the user the opportunity...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and show they will translate and run. Experience error messages when you enter bad syntax the interpreter cannot understand. Discussion: The best way to learn Python (or any programming language) is to write & run Python programs. In this lab you will enter two programs, and run them to produce the output. Then deliberately insert syntax errors to see what kinds of error messages you...
How do I write a script for this in python in REPL or atom, NOT python...
How do I write a script for this in python in REPL or atom, NOT python shell Consider the following simple “community” in Python . . . triangle = [ ["top", [0, 1]], ["bottom-left", [0, 0]], ["bottom-right", [2, 0]], ] This is the calling of function. >>> nearestneighbor([0, 0.6], triangle, myeuclidean) 'top' The new point is (0, 0.6) and the distance function is Euclidean. Now let’s confirm this result . . . >>> myeuclidean([0, 0.6], [0, 1]) 0.4 >>> myeuclidean([0,...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the...
Please write a python code for the following. Use dictionaries and list comprehensions to implement the functions defined below. You are expected to re-use these functions in implementing other functions in the file. Include a triple-quoted string at the bottom displaying your output. Here is the starter outline for the homework: a. def count_character(text, char): """ Count the number of times a character occurs in some text. Do not use the count() method. """ return 0 b. def count_sentences(text): """...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT