Question

In: Computer Science

Write python 3 code to define a function that uses three arguments, and returns a result....

Write python 3 code to define a function that uses three arguments, and returns a result.

The function returns True if the first argument is more than or equal to the second argument and less than or equal to the third argument, otherwise it returns False.

Write a python 3 code for function main, that does the following:

  • creates a variable and assign it the value True.
  • uses a while loop which runs as long as the variable of the previous step is True,
  • inside the while loop, get a number from the user and
  • if passing that number to the function of the previous question along with 0 and 10, results in a True value returned, then add that number to a running sum. Otherwise make the loop stop without using break.
  • After the loop stops, print the running sum of all the values the user entered.

Call main at the end.

Make sure to use conversion or casting functions as needed.

Solutions

Expert Solution

Dear Student ,

As per requirement submitted above kindly find below solution.

Python program :

#Python function
def compareNumber(number1,number2,number3):
    #check numbers
    if number1>=number2 and number1<=number3:
        #if the first argument is more than or equal to the
        # second argument and less than or equal to the third argument
        return True
    else :
        return False
#main() function
def main():
    flag=True #loop variable
    sum=0 #declared variable to store sum
    #using while loop
    while(flag):
        #asking user to enter a number
        number=int(input("Enter a number : "))
        #calling function and pass the number
        if(compareNumber(number,0,10)):
            #if compareNumber() returns true then
            #add to the variable sum
            sum=sum+number
        else:
            flag=False #set flag to false
    #print sum
    print("Sum : ",sum)
#call main() function
main()

****************************************

Please refer to the screenshot of the code to understand the indentation of the code :

==================================

Output :

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Write code to define a function named mymath. The function has three arguments in the following...
Write code to define a function named mymath. The function has three arguments in the following order: Boolean, Integer, and Integer. It returns an Integer. The function will return a value as follows: 1. If the Boolean variable is True, the function returns the sum of the two integers. 2. If the Boolean is False, then the function returns the value of the first integer - the value of the second Integer.
Write a Python function that accepts three arguments: an array, the size of the array, and...
Write a Python function that accepts three arguments: an array, the size of the array, and a number n. Assume that array contains integers. The function should display all integers in the array that are greater than the number n. Test your function.
python 3 please Define a function voweliest that takes as input a string and returns as...
python 3 please Define a function voweliest that takes as input a string and returns as output a tuple where the string that has the most vowels in it is the first element and the second is the number of vowels in that string. Note: don't worry about ties or capital letters Hint: consider defining and using a separate function that counts the number of vowels in a given string
Make a python code. Write a function named max that accepts two integer values as arguments...
Make a python code. Write a function named max that accepts two integer values as arguments and returns the value that is the greater of the two. For example, if 7 and 12 are passed as arguments to the function, the function should return 12. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is the greater of the two. Write the program as a loop that...
I am trying to write a python code to create a function that returns all possible...
I am trying to write a python code to create a function that returns all possible dimensions (reshaping) for an input matrix, can someone explains the math and write a python code with explaining all the steps and give me a test cases, and please explain if there is more than one approach. so if we have 1*8 matrix we should return 1*8, 2*4,4*2,8*1 def reshaping(M) should return a n ORDERED list AND the all possible reshaped matrices
Write a Python function that takes a list of string as arguments. When the function is...
Write a Python function that takes a list of string as arguments. When the function is called it should ask the user to make a selection from the options listed in the given list. The it should get input from the user. Place " >" in front of user input. if the user doesn't input one of the given choices, then the program should repeatedly ask the user to pick from the list. Finally, the function should return the word...
Write code in Python: The edge-detection function (detectEdges) described in Chapter 7 and shown below returns...
Write code in Python: The edge-detection function (detectEdges) described in Chapter 7 and shown below returns a black and white image. Think of a similar way to transform color values so that the new image is still in its original colors but the outlines within it are merely sharpened. Then, define a function named sharpen that performs this operation. The function should expect an image and two integers as arguments. One integer should represent the degree to which the image...
The header of a Python function is shown below: def result(one, two, three = 3, four)...
The header of a Python function is shown below: def result(one, two, three = 3, four) (a) How do we call the situation with the third parameter in this header? (b) Indicate the method of correspondence between formal and actual parameters that is used in the following function call: result(four = 14, two = 22, one = 1, three = 33) (c) Explain what is wrong with the following function call: result(14, four = 44, 2, 3)
Python: Write a function that receives a one dimensional array of integers and returns a Python...
Python: Write a function that receives a one dimensional array of integers and returns a Python tuple with two values - minimum and maximum values in the input array. You may assume that the input array will contain only integers and will have at least one element. You do not need to check for those conditions. Restrictions: No built-in Python data structures are allowed (lists, dictionaries etc). OK to use a Python tuple to store and return the result. Below...
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns...
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns the number of 1's in the binary representation of n. Use the fact that this is equal to the number of 1's in the representation of n//2 (integer division) plus 1 if n is odd. >>>numOnes(0) 0 >>>numOnes(1) 1 >>>numOnes(14) 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT