Challenge to all programmers
From this question I am challenging all the python programmers here on brainly to create your own function named great which will find the greatest of all the input values ( just like max function). It may accept n number of values ( n= ∞ ). It is optional for your program to work for English Alphabets. But it should word good for floats and integers.
Accept this challenge if you're are real programmer.
Answers
Question : -
To create a program which should have defined function called great to find the greatest value of all the input values. The number of inputs which can be taken has no limit. This should work with both floats and integers.
Answer
Required to do :
- Take input from user.
- Find the greatest value from all input values.
Constraints
- It should work for both float and integer data types
Program :
print('''
This loop runs infinite times
Inorder, to stop it use phrase stop
''')
i = 0
vals = [ ]
while i <= 10:
user_input = input("Enter a value :- ")
if user_input == "stop" :
break #stops the loop
else:
new_vals = vals.append(user_input)
#due to no increment the above loop runs infinite times
#creating the required function
def great(list):
list.sort() #arranges the values of list in ascending order
return list[-1] #prints the last value of list
result= great(vals)
print(" \n \n The maximum value is {}".format(result))
Output
(Refer to attachment )
The following codes have been written using Python.
There are two types of functions available in Python.
- Inbuilt functions - readymade functions built by Python that can be used by directly calling them.
- User-defined functions - functions created by programmers for a specific purpose.
In this case, we use to define a function. Once it is called, it asks for input from the user. The input loop continues as long as the while condition results to True. Once the user inputs the restriction value, the loop stops. The list then returns the highest value from the list, using the function that is an in-built function designed for the same purpose.