In: Computer Science
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:
Call main at the end.
Make sure to use conversion or casting functions as needed.
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.