Question: I need to write a function that accepts three numbers, and returns which number has the maximum value. If more than one maximum value exists,
I need to write a function that accepts three numbers, and returns which number has the maximum value. If more than one maximum value exists, the script can return either maximum number. I have to use this function in a Python script that asks the user for three numbers to be input (one at a time), uses the function to determine maximum value, and then displays that maximum value. The script should continue until the user types the word exit as the first number. How do I get it to loop back to the first input for number 1 and accept exit to end? I cannot use the max() function. This is what I have so far:
def maxValue(a,b,c): if a>b and a>c : print("This number has the highest value=",a) if b>a and b>c: print("This number has the highest value=",b) if c>a and c> b: print("This number has the highest value=",c) #asks the user to enter three numbers print('Welcome to the Maximum Value Determination Program') print('To find the maximum value of three numbers, ') print('start by inputing each number one at a time and press enter.')
a=int(input('Enter the first number: ')) b=int(input('Enter the second number: ')) if a==b: print("You have entered the same value twice.") c=int(input('Enter the third number: ')) if a==b: print("You have entered the same value twice.") if b==c: print("You have entered the same value twice.") elif a==b==c: print('All three values are the same.') while True: maxValue(a,b,c) if a>b and a>c or a==b: print('a' + ' is the maximum value.') if b>a and b>c or b==a: print('b' + ' is the maximum value.') if c>a and c>b: print('c' + ' is the maximum value.') break
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
