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
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...
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
In PYTHON: Write a function that receives a sentence and returns the last word of that...
In PYTHON: Write a function that receives a sentence and returns the last word of that sentence. You may assume that there is exactly one space between every two words, and that there are no other spaces at the sentence. To make the problem simpler, you may assume that the sentence contains no hyphens, and you may return the word together with punctuation at its end.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT