Skip to content

Commit 378da46

Browse files
committed
Use print() function in both Python 2 and Python 3
1 parent f44b26c commit 378da46

File tree

8 files changed

+35
-27
lines changed

8 files changed

+35
-27
lines changed

Guess_the_number_game.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
# using codeSkulpter
23

34
import simplegui
@@ -23,7 +24,7 @@ def range_of_1000():
2324

2425
def input_guess(guess):
2526
global num
26-
print("Your Guess is " , guess)
27+
print(("Your Guess is " , guess))
2728
num1 = int(guess)
2829
if num1 == num:
2930
print("Correct")

WikipediaModule.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
@author: Albert
55
"""
6+
from __future__ import print_function
67
import wikipedia as wk
78
from bs4 import BeautifulSoup
89

@@ -14,7 +15,7 @@ def wiki():
1415
word=raw_input("Wikipedia Search : ")
1516
results=wk.search(word)
1617
for i in enumerate(results):
17-
print i
18+
print(i)
1819
try:
1920
key=input("Enter the number : ")
2021
except AssertionError:
@@ -30,12 +31,12 @@ def wiki():
3031
pageLength=input('''Wiki Page Type : 1.Full 2.Summary : ''')
3132
if pageLength==1:
3233
soup=fullPage(page)
33-
print soup
34+
print(soup)
3435
else:
35-
print title
36-
print "Page Id = ",pageId
37-
print page.summary
38-
print "Page Link = ",url
36+
print(title)
37+
print("Page Id = ",pageId)
38+
print(page.summary)
39+
print("Page Link = ",url)
3940
#print "References : ",references
4041

4142

@@ -53,7 +54,7 @@ def randomWiki():
5354
number=input("No: of Random Pages : ")
5455
lst=wk.random(number)
5556
for i in enumerate(lst):
56-
print i
57+
print(i)
5758
try:
5859
key=input("Enter the number : ")
5960
assert key>=0 and key<number
@@ -70,12 +71,12 @@ def randomWiki():
7071
pageLength=input('''Wiki Page Type : 1.Full 2.Summary : ''')
7172
if pageLength==1:
7273
soup=fullPage(page)
73-
print soup
74+
print(soup)
7475
else:
75-
print title
76-
print "Page Id = ",pageId
77-
print page.summary
78-
print "Page Link = ",url
76+
print(title)
77+
print("Page Id = ",pageId)
78+
print(page.summary)
79+
print("Page Link = ",url)
7980
#print "References : ",references
8081

8182
pass

check_internet_con.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/python3
22

3+
from __future__ import print_function
34
try:
45
# For Python 3.0 and later
56
from urllib.request import urlopen

communication/pipe.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding: utf-8
22

3+
from __future__ import print_function
34
import os
45
import sys
56
import math
@@ -38,5 +39,5 @@ def pi(n):
3839
return math.sqrt(sum(sums) * 8)
3940

4041

41-
print pi(10000000)
42+
print(pi(10000000))
4243

communication/socket_conn.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding: utf-8
22

3+
from __future__ import print_function
34
import os
45
import sys
56
import math
@@ -36,4 +37,4 @@ def pi(n):
3637
return math.sqrt(sum(sums) * 8)
3738

3839

39-
print pi(10000000)
40+
print(pi(10000000))

internet_connection_py3.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
from __future__ import print_function
12
import urllib2
23
import os
34
from selenium import webdriver
45
from selenium.webdriver.common.keys import Keys
5-
print "Testing Internet Connection"
6-
print
6+
print("Testing Internet Connection")
7+
print()
78
try:
89
urllib2.urlopen("http://google.com", timeout=2)#Tests if connection is up and running
9-
print "Internet is working fine!"
10-
print
10+
print("Internet is working fine!")
11+
print()
1112
question = raw_input("Do you want to open a website? (Y/N): ")
1213
if question == 'Y':
13-
print
14+
print()
1415
search = raw_input("Input website to open (http://website.com) : ")
1516
else:
1617
os._exit(0)
@@ -21,5 +22,5 @@
2122
browser = webdriver.Firefox()
2223
browser.get(search)
2324
os.system('cls')#os.system('clear') if Linux
24-
print "[+] Website "+search + " opened!"
25+
print("[+] Website "+search + " opened!")
2526
browser.close()

movie_details.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
import mechanize
23
import urllib2
34
from bs4 import BeautifulSoup

rock_paper_scissor_game.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from __future__ import print_function
12
#let
23
# 0 - rock
34
# 1 - paper
@@ -23,21 +24,21 @@ def number_to_name(number):
2324
return "scissors"
2425

2526
def game(player_choice):
26-
print
27+
print()
2728
name = player_choice
28-
print name
29+
print(name)
2930
number = name_to_number(name)
3031
comp_number = random.randrange(0,2)
3132
comp_choice = number_to_name(comp_number)
32-
print comp_choice
33+
print(comp_choice)
3334

3435
comp = -int(comp_number)
3536
play = int(number)
3637
diff = (comp + play)%5
3738

3839
if diff == 1 or diff == 3:
39-
print "you won!!!"
40+
print("you won!!!")
4041
elif diff == 0:
41-
print "draw"
42+
print("draw")
4243
elif diff == 2 or diff == 4:
43-
print "you lose!!!"
44+
print("you lose!!!")

0 commit comments

Comments
 (0)