Question

In: Computer Science

Q.1: create a python function that takes two integers from the user ( pass them from...

Q.1: create a python function that takes two integers from the user ( pass them from the main program). The function performs the addition operation and returns the result. In the program, ask the user to guess the result. Then, the program compares the user input ( guess) with the returned value, and displays a message that tells if the user guessing is correct or not.

--define the function here ---

# the program starts here

print(“ This program tests your knowledge of the addition operation:”)

number1, number2 =input (“ Enter two numbers: “). ????? # complete the input statement by replacing #????

theNumber1 =int(number1)

theNumber2 =int(number2)

guess = float(input(“Enter your guess of adding the two numbers: “))

---call the function---

---- compare here-----

---- display the message-----

create a python function (only) that generates 10 random numbers within a specific range. Every time a number is generated, it is appended to a list (you need to initialize a list). Then the function counts how many times a number is repeated in the created list (you can choose any number to count). The function returns the list, the number you have chosen and its count.

--define the function here ---

Call the following function twice by passing a tuple of int and tuple of float:

def average(*args):

return sum(args) / len(args)

Solutions

Expert Solution

Code and output

Code fot copying

def addition(theNumber1,theNumber2):
c=theNumber1+theNumber2
return c
print("This program tests your knowledge of the addition operation")
number1, number2 =input ("Enter two numbers: ").split(' ')
theNumber1 =int(number1)
theNumber2 =int(number2)
guess = float(input("Enter your guess of adding the two numbers: "))
print("The addition of two numbers is {}".format(addition(theNumber1,theNumber2)))
if addition(theNumber1,theNumber2)==guess:
print("Your guess is correct")
if addition(theNumber1,theNumber2)!=guess:
print("Your guess is not correct")

Code snippet

def addition(theNumber1,theNumber2):
    c=theNumber1+theNumber2
    return c
print("This program tests your knowledge of the addition operation")
number1, number2 =input ("Enter two numbers: ").split(' ')
theNumber1 =int(number1)
theNumber2 =int(number2)
guess = float(input("Enter your guess of adding the two numbers: "))
print("The addition of two numbers is {}".format(addition(theNumber1,theNumber2)))
if addition(theNumber1,theNumber2)==guess:
    print("Your guess is correct")
if addition(theNumber1,theNumber2)!=guess:
    print("Your guess is not correct")


Related Solutions

python practice! 1. Create a function that takes a user choice and one number as parameters...
python practice! 1. Create a function that takes a user choice and one number as parameters and returns the operation result. -Square: print the number square -Sqrt: print the square root of the number -Reverse: reverse the sign of the number (pos or neg) and print it Note: Detect invalid choices and throw an error message – Number can be anything. 2. Create a function that takes a user choice and two numbers (start and end) as parameters. For example,...
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
In C++, create a function exchangesl that takes an argument of an array of integers (...
In C++, create a function exchangesl that takes an argument of an array of integers ( for C++ use implement void exchangesl(vector<int>& a) . Those integers need to be changed so that the smallest and largest values in the array are exchanged. Assume that there is at least one element, if the largest value occurs more than once then exchange the first instance, if the smallest value happens more than once then exchange the last instance.
In C++, create a function exchangesl that takes an argument of an array of integers (...
In C++, create a function exchangesl that takes an argument of an array of integers ( for C++ use implement void exchangesl(vector<int>& a) . Those integers need to be changed so that the smallest and largest values in the array are exchanged. Assume that there is at least one element, if the largest value occurs more than once then exchange the first instance, if the smallest value happens more than once then exchange the last instance. Use the following file:...
. Create a Python function that asks the user for a number (integer). The function should...
. Create a Python function that asks the user for a number (integer). The function should then tell the user how many hundreds can go into the number, and how much is left over. Hint: the % operator calculates the remainder of a division. For example, 10 % 3 gives a result 1. Hint2: Deal with the positive and negative values in separate parts of an if-else structure. Get the calculation work for positive values first. For negative values, make...
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return the linked list unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly and then return the linked list with the modifications, not a list. If you have a linked list 11 -> 12 -> 18 -> 20...
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return head unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly. If you have a linked list 11 -> 12 -> 18 -> 20 -> 24 -> 32 -> 38 -> 44 and skip =2, then you should...
Create a Python program that will take an unsorted list of 1000 integers and sort them...
Create a Python program that will take an unsorted list of 1000 integers and sort them using a bubble sort and an insertion sort. Your output should include displaying both sorted lists (from each algorithm) identifying each sorted list by the algorithm used.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT