jmelahman/python-for-everybody-solutions

How can my Print syntax says SyntaxError: invalid syntax ?

Closed this issue · 1 comments

I using Google Colaboratory and this happening
Screenshot_1

This is the code i write:


import numpy as np
from google.colab import files
from keras.preprocessing import image
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
%matplotlib inline

uploaded = files.uploaded()

for fn in uploaded.keys():
path = fn
img = image.load_img(path, target_size=(150, 150))
imgplot = plt.imshow(img)
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
classes = model.predict(images, batch_size=10
print("hello world")
print(fn)
if classes==0:
print('The room was Clean')
else:
print('The room was Messy')


Thank you for helping me.

If you haven't figured it out, you're likely using python2. If you can change the interpreter to use major version 3, that should fix it. You can check which version you're using with,

$ cat version.py 
import sys
print(sys.version)

$ python2 version.py 
2.7.18 (default, Sep  5 2020, 11:17:26) 
[GCC 10.2.0]

$ python3 version.py
3.8.6 (default, Sep 30 2020, 04:00:38) 
[GCC 10.2.0]

Alternatively, you can import the python3 print function from the future, https://stackoverflow.com/a/32032727.