Python Forum
I need help fixing a syntax error!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need help fixing a syntax error!
#1
Hi! Can someone help me fix this python code! I don't know why their is a syntax error on print colored. I need this tomorrow so please bless me with the Christmas love and spirit by helping me.

Here's the whole code:
import neurolab as nl
import numpy as np
from termcolor import colored

#read inputs and targets
f = open("megamillions.csv",'r')
input = []
line_count = 0
for line in f.readlines():
 line = line.split(',')
 line_count += 1
 if line_count > 0: #don't skip line 1
  
  lineinput = [0] * 75
  for i in range(4,9):
   lineinput[int(line[i])-1] = 1
  input.append(lineinput)

#set target outputs for training to be from row 1 to end of list, skipping first row 0
target = input[1:len(input)]
#set siminput to be last row of input to use for simulation to predict output
siminput = [input[len(input)-1]]

#set input, make input one row less since the last row wouldn't have target output
input = input[0:len(input)-1]


#make it numpy
target = np.array(target)
input = np.array(input)
siminput = np.array(siminput)


def output(o):
 array = o[0]
 order = array.argsort()
 #ranks = order.argsort()
 
 for i in range(74,-1,-1):
  index = order[i] + 1
  print colored(str(index),"green") + colored("(" + str(int(array[index-1] * 1000)/1000.0) + ")","red"),
  if i % 5 == 0:
   print
 print 
 
net = nl.load("one.net")
print colored("Mega Million","blue") + colored(" number","green") + colored("(probability)","red")
out = net.sim(siminput)
output(out)
while True:
 net = nl.load("one.net")
 print "Training..."
 error = net.train(input,target,epochs=10,show=1)
 
 # with line below we can specify training to stop when error[0] is smaller than goal it stops
 # but since we're inside a forever loop, there's no need to specify goal.
 # error = net.train(input,target,epochs=10,show=1,goal=0.01)
 
 # just a fail safe, just an extra save so that if we Ctrl-C while we're saving we'll have at least copy of latest network that works
 net.save("one.net.bk")
 net.save("one.net")
 
 print colored("Mega Million","blue") + colored(" number","green") + colored("(probability)","red")
 out = net.sim(siminput)
 
 #output for display purposes only
 output(out)
Here is the display output error:
Error:
File "C:/Users/Yip/Desktop/MEGA_NN/run.py", line 41 print colored(str(index),"green") + colored("(" + str(int(array[index-1] * 1000)/1000.0) + ")","red"), ^ SyntaxError: invalid syntax
Thanks so much to anyone willing to help with great knowledge of python!
Of course happy holidays!
Reply
#2
why python 2.7? end of life is in 6 days! see: https://pythonclock.org/
termcolor is as old as the hills, hasn't been updated since January 2011

instead, use python 3 and colorama: https://pypi.org/project/colorama/
Reply
#3
i dont know python2 very well
but i think the comma on the end of row 41 shouldnt be there
Reply
#4
get away from python 2! End of life now less than 6 days!
Reply
#5
In six days, Python3 users party while Python2 users riot!
Reply
#6
It will be a small riot.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Statsmodels Multiple Regression Syntax Error Burger 2 2,813 Jul-13-2021, 03:04 AM
Last Post: Burger
  New to Pandas. I need help fixing a TypeError kramon19 1 1,786 Dec-30-2020, 02:20 PM
Last Post: snippsat
  How to find what is causing the unboundlocalerror 'crumb' and invalid syntax error? JonathanBanks 1 2,292 Jul-28-2020, 11:46 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020