Skip to content

Commit 22a18f4

Browse files
committed
Use print() function in both Python 2 and Python 3
1 parent a7853b7 commit 22a18f4

File tree

7 files changed

+96
-80
lines changed

7 files changed

+96
-80
lines changed

Colors/primary_colors.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
def diff(a, b):
2+
"""
3+
TODO: fix this function!!
4+
"""
5+
return a - b
6+
7+
18
def simpleColor(r,g,b):
2-
""" simpleColor obtiene el nombre del color mas general al cual se acerca su formato R G B """
9+
""" simpleColor obtiene el nombre del color mas general al cual se acerca su formato R G B """
310
r=int(r)
411
g=int(g)
512
b=int(b)
13+
bg = ir = 0 # TODO: Fix these variables
614
try:
715
#ROJO --------------------------------------------------
816
if r > g and r > b:
@@ -18,21 +26,21 @@ def simpleColor(r,g,b):
1826
if rg < rb: # Verde mayor que Azul
1927
if gb < rg: #Verde mas cerca de Azul
2028
if gb >=30 and rg >= 80:
21-
return "NARANJA"
29+
return "NARANJA"
2230
elif gb<=20 and rg >= 80:
2331
return "ROJO"
2432
elif gb<=20 and b > 175:
2533
return "CREMA"
2634

2735
else:
28-
return "CHOCOLATE"
36+
return "CHOCOLATE"
2937
else: #Verde mas cerca de Rojo
30-
if rg > 60:
31-
return "NARANJA*"
32-
elif r > 125:
33-
return "AMARILLO"
34-
else:
35-
return "COCHOLATE"
38+
if rg > 60:
39+
return "NARANJA*"
40+
elif r > 125:
41+
return "AMARILLO"
42+
else:
43+
return "COCHOLATE"
3644
elif rg > rb: #Azul mayor que verde
3745
if bg < rb: #Verde mas cerca de Azul
3846
if gb < 60:
@@ -43,7 +51,7 @@ def simpleColor(r,g,b):
4351
elif g > 125:
4452
return "ROSADO"
4553
else:
46-
return "ROJO 3"
54+
return "ROJO 3"
4755
else: #Verde mas cerca de Rojo
4856
if rb < 60:
4957
if r > 160:
@@ -77,21 +85,21 @@ def simpleColor(r,g,b):
7785
if r > b: #ROJO > AZUL
7886
if gr < gb: #Verde con Rojo
7987

80-
if rb>=150 and gr <=20:
88+
if rb>=150 and gr <=20:
8189
return "AMARILLO"
8290
else:
8391
return "VERDE"
84-
else: #...Verde
92+
else: #...Verde
8593
return "VERDE"
8694

8795
elif r < b: #AZUL > ROJO
8896
if gb < gr: #Verde con Azul
8997

90-
if gb<=20:
98+
if gb<=20:
9199
return "TURQUESA"
92100
else:
93101
return "VERDE"
94-
else: #...Verde
102+
else: #...Verde
95103
return "VERDE"
96104

97105
else: #r y b iguales
@@ -112,12 +120,12 @@ def simpleColor(r,g,b):
112120
rg=diff(r,g) #distancia de rojo a verde
113121

114122
if g < r: # ROJO > VERDE
115-
if bg < rg: #Azul con Verde
116-
if bg<=20:
123+
if bg < rg: #Azul con Verde
124+
if bg<=20:
117125
return "TURQUESA"
118126
else:
119127
return "CELESTE"
120-
else: #...Azul
128+
else: #...Azul
121129
if rg <= 20:
122130
if r >= 150:
123131
return "LILA"
@@ -144,7 +152,7 @@ def simpleColor(r,g,b):
144152
if bg <=20:
145153
return "GRIS"
146154
else:
147-
return "AZUL"
155+
return "AZUL"
148156
else: #r y g iguales
149157
if bg > 20:
150158
if r>=100 and b <60:
@@ -157,7 +165,7 @@ def simpleColor(r,g,b):
157165
return "GRIS"
158166

159167

160-
# IGUALES---------------------------------------
168+
# IGUALES---------------------------------------
161169
else:
162170
return "GRIS"
163171

@@ -170,4 +178,5 @@ def simpleColor(r,g,b):
170178
# Puedes probar asi: python primary_colors.py 120,0,0 , esto resultara en un ROJO como respuesta
171179
#--------------------------------------------------------------------------------------------------
172180
if __name__=='__main__':
173-
print(simpleColor(sys.argv[1],sys.argv[2],sys.argv[3]))
181+
import sys
182+
print(simpleColor(sys.argv[1],sys.argv[2],sys.argv[3]))

blackJackGUI.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import random
21

2+
from __future__ import print_function
3+
import random
4+
import simplegui
35
CARD_SIZE = (72, 96)
46
CARD_CENTER = (36, 48)
57
card_images = simplegui.load_image("http://storage.googleapis.com/codeskulptor-assets/cards_jfitz.png")
@@ -21,7 +23,7 @@ def __init__(self, suit, rank):
2123
else:
2224
self.suit = None
2325
self.rank = None
24-
print("Invalid card: ", suit, rank)
26+
print(("Invalid card: ", suit, rank))
2527

2628
def __str__(self):
2729
return self.suit + self.rank

convert_time.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Created by sarathkaul on 12/11/19
23

34

@@ -22,5 +23,5 @@ def convert_time(input_str):
2223

2324

2425
if __name__ == '__main__':
25-
input_time = str(raw_input("Enter time you want to convert: "))
26+
input_time = input("Enter time you want to convert: ")
2627
print(convert_time(input_time))

fetch_news.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Created by sarathkaul on 11/11/19
23

34
import requests
@@ -20,7 +21,7 @@ def fetch_bbc_news():
2021

2122
for a_result in range(len(results)):
2223
# printing all trending news
23-
print str(a_result + 1) + ".) ", results[a_result]['title']
24+
print(str(a_result + 1) + ".) ", results[a_result]['title'])
2425

2526

2627
if __name__ == '__main__':

psunotify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36')]
1111
br.set_handle_robots(False)
1212
# For page exploration
13-
page = raw_input('Enter Page No:')
13+
page = input('Enter Page No:')
1414
# print type(page)
1515
p = urllib2.Request('https://www.google.co.in/search?q=gate+psu+2017+ext:pdf&start=' + page)
1616
ht = br.open(p)

sendemail.py

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from __future__ import print_function
22

33
import base64
4+
import mimetypes
45
import os
6+
from email.mime.audio import MIMEAudio
7+
from email.mime.base import MIMEBase
8+
from email.mime.image import MIMEImage
59
from email.mime.multipart import MIMEMultipart
610
from email.mime.text import MIMEText
711

@@ -58,66 +62,64 @@ def SendMessageInternal(service, user_id, message):
5862
return "Error"
5963
return "OK"
6064

61-
# Create Mail With AttAchment Remove hash to make the code readable
62-
# def createMessageWithAttachment(
63-
# sender, to, subject, msgHtml, msgPlain, attachmentFile):
65+
66+
def createMessageWithAttachment(
67+
sender, to, subject, msgHtml, msgPlain, attachmentFile):
6468
"""Create a message for an email.
6569
6670
Args:
67-
sender: Email address of the sender.
68-
to: Email address of the receiver.
69-
subject: The subject of the email message.
70-
msgHtml: Html message to be sent
71-
msgPlain: Alternative plain text message for older email clients
72-
attachmentFile: The path to the file to be attached.
71+
sender: Email address of the sender.
72+
to: Email address of the receiver.
73+
subject: The subject of the email message.
74+
msgHtml: Html message to be sent
75+
msgPlain: Alternative plain text message for older email clients
76+
attachmentFile: The path to the file to be attached.
7377
7478
Returns:
75-
An object containing a base64url encoded email object.
79+
An object containing a base64url encoded email object.
7680
"""
77-
78-
79-
# message = MIMEMultipart('mixed')
80-
# message['to'] = to
81-
# message['from'] = sender
82-
# message['subject'] = subject
83-
84-
# messageA = MIMEMultipart('alternative')
85-
# messageR = MIMEMultipart('related')
86-
87-
# messageR.attach(MIMEText(msgHtml, 'html'))
88-
# messageA.attach(MIMEText(msgPlain, 'plain'))
89-
# messageA.attach(messageR)
90-
91-
# message.attach(messageA)
92-
93-
# print "create_message_with_attachment: file:", attachmentFile
94-
# content_type, encoding = mimetypes.guess_type(attachmentFile)
95-
96-
# if content_type is None or encoding is not None:
97-
# content_type = 'application/octet-stream'
98-
# main_type, sub_type = content_type.split('/', 1)
99-
# if main_type == 'text':
100-
# fp = open(attachmentFile, 'rb')
101-
# msg = MIMEText(fp.read(), _subtype=sub_type)
102-
# fp.close()
103-
# elif main_type == 'image':
104-
# fp = open(attachmentFile, 'rb')
105-
# msg = MIMEImage(fp.read(), _subtype=sub_type)
106-
# fp.close()
107-
# elif main_type == 'audio':
108-
# fp = open(attachmentFile, 'rb')
109-
# msg = MIMEAudio(fp.read(), _subtype=sub_type)
110-
# fp.close()
111-
# else:
112-
# fp = open(attachmentFile, 'rb')
113-
# msg = MIMEBase(main_type, sub_type)
114-
# msg.set_payload(fp.read())
115-
# fp.close()
116-
# filename = os.path.basename(attachmentFile)
117-
# msg.add_header('Content-Disposition', 'attachment', filename=filename)
118-
# message.attach(msg)
119-
120-
# return {'raw': base64.urlsafe_b64encode(message.as_string())}
81+
message = MIMEMultipart('mixed')
82+
message['to'] = to
83+
message['from'] = sender
84+
message['subject'] = subject
85+
86+
messageA = MIMEMultipart('alternative')
87+
messageR = MIMEMultipart('related')
88+
89+
messageR.attach(MIMEText(msgHtml, 'html'))
90+
messageA.attach(MIMEText(msgPlain, 'plain'))
91+
messageA.attach(messageR)
92+
93+
message.attach(messageA)
94+
95+
print("create_message_with_attachment: file:", attachmentFile)
96+
content_type, encoding = mimetypes.guess_type(attachmentFile)
97+
98+
if content_type is None or encoding is not None:
99+
content_type = 'application/octet-stream'
100+
main_type, sub_type = content_type.split('/', 1)
101+
if main_type == 'text':
102+
fp = open(attachmentFile, 'rb')
103+
msg = MIMEText(fp.read(), _subtype=sub_type)
104+
fp.close()
105+
elif main_type == 'image':
106+
fp = open(attachmentFile, 'rb')
107+
msg = MIMEImage(fp.read(), _subtype=sub_type)
108+
fp.close()
109+
elif main_type == 'audio':
110+
fp = open(attachmentFile, 'rb')
111+
msg = MIMEAudio(fp.read(), _subtype=sub_type)
112+
fp.close()
113+
else:
114+
fp = open(attachmentFile, 'rb')
115+
msg = MIMEBase(main_type, sub_type)
116+
msg.set_payload(fp.read())
117+
fp.close()
118+
filename = os.path.basename(attachmentFile)
119+
msg.add_header('Content-Disposition', 'attachment', filename=filename)
120+
message.attach(msg)
121+
122+
return {'raw': base64.urlsafe_b64encode(message.as_string())}
121123

122124

123125
def CreateMessageHtml(sender, to, subject, msgHtml, msgPlain):

slack_message.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
# Created by sarathkaul on 11/11/19
23

34
import json
@@ -8,7 +9,7 @@
89
slack_data = {'text': "Hi Sarath Kaul"}
910

1011
response = urllib.request.Request(webhook_url, data=json.dumps(slack_data),headers={'Content-Type': 'application/json'})
11-
print response
12+
print(response)
1213
# if response.status_code != 200:
1314
# raise ValueError(
1415
# 'Request to slack returned an error %s, the response is:\n%s'

0 commit comments

Comments
 (0)