Computer Science, asked by Anonymous, 6 hours ago

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

Answered by MisterIncredible
18

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 )

Attachments:
Answered by Equestriadash
19

The following co‎des have been written using Python.

\tt d ef\ great():\\{\ \ \ \ \ }    l\ =\ list()\\{\ \ \ \ \ }   while\ True:\\{\ \ \ \ \ }{\ \ \ \ \ }        n\ =\ eval(in put("Enter\ the\ data/Type\ 'S'\ to\ stop:\ "))\\{\ \ \ \ \ }{\ \ \ \ \ }        if\ n\ ==\ 'S':\\{\ \ \ \ \ }{\ \ \ \ \ }{\ \ \ \ \ }            break\\{\ \ \ \ \ }{\ \ \ \ \ }       l.append(n)\\    {\ \ \ \ \ }print(max(l))\\great()\\

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 \tt d ef 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 \tt max() function that is an in-built function designed for the same purpose.

Similar questions