Using Python 3: On the NASA space shuttle, three computers were in use simultane
ID: 3855689 • Letter: U
Question
Using Python 3:
On the NASA space shuttle, three computers were in use simultaneously. Computations were performed by all three computers, and the result of each computation was put to a vote. If at least two of the computers provided the same result, then that result was used. But if all computers each provided a different result, then the computation was discarded.
Write a function that has three parameters whose values represent three different computational results. If at least two of the inputs are the same, your function should return that value. If all three are different, return the word "ERROR" instead. Write a main() that tests your function extensively.
Explanation / Answer
def check(val1,val2,val3): #parameterised function
if val1==val2 : #condition to check for two same values
return val1
elif val1==val3:
return val1
elif val2==val3:
return val2
else:
str="ERROR" #if no two condtion is matched then error is returned
return str
s1=check(3,3,3) #callig the function with the parameter
print(s1)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.