-2

I am trying to find the max and min of a list of random numbers without using any built in functions. I have this code, but its showing an invalid syntax error on the last line. Can someone help? Using spyder in python 3.7. Also I know that the random number list works, just the min code is not working.

import random

l = []

for i in range(0,50):
    x = random.randint(1,10)
    l.append(x)

print(l)

def minimum(list):
  current_min = list[0]  
  for num in list:       
    if num < current_min:
      current_min = num  
  return current_min

print minimum(l)
Annsley
  • 1
  • 1
  • 1
    What error? Please provide as much information as you can. Is this Python 3? Did you do any research before posting? – juanpa.arrivillaga Mar 31 '20 at 20:55
  • Please repeat the intro tour, especially [MRE](https://stackoverflow.com/help/minimal-reproducible-example). – Prune Mar 31 '20 at 20:57
  • You should include the exact error message in the question. It cuts down on the ambiguity. I can tell what you meant, but you're still getting questions about it, for good reason. – Kenny Ostrom Mar 31 '20 at 21:06
  • see https://stackoverflow.com/questions/826948/syntax-error-on-print-with-python-3 and https://stackoverflow.com/a/49638320/1766544 – Kenny Ostrom Mar 31 '20 at 21:07

2 Answers2

0

Assuming you are using python 3, then I expect the last line is returning an error because you are missing the brackets on the print statement, it should be

print (minimum(l))

On another note, you can also shorten the initialization of your list into a one-liner

l = [random.randint(1, 10) for x in range(50)]
incarnadine
  • 658
  • 7
  • 19
0

In python3, you should use print with parenthesis. Change your last line to be print(minimum(l))

Gabio
  • 9,126
  • 3
  • 12
  • 32