Skip to content

Commit 81ab2d3

Browse files
author
shreydan
committed
Python 2.7 -> 3.5
1 parent 82ebea6 commit 81ab2d3

File tree

11 files changed

+84
-85
lines changed

11 files changed

+84
-85
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Python
1+
# Python Scripts
22

3-
All programs are written in Python 2.7
3+
All programs are written in Python 3.5
44

55
## to install modules run:
66

code/API/Tweepy (Twitter)/tweets.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010
Have fun, this code is all yours.
1111
NEVER SHARE YOUR CONSUMER KEY SECRET AND ACCESS TOKEN SECRET!!!
1212
"""
13+
1314
import tweepy, os
1415

1516
def tweetthis(type):
1617
if type == "text":
17-
print "Enter your tweet "+user.name
18-
tweet = raw_input()
18+
print ("Enter your tweet "+user.name)
19+
tweet = input()
1920
api.update_status(tweet)
2021
elif type == "pic":
21-
print "Enter pic path "+user.name
22-
pic = os.path.abspath(raw_input())
23-
print "Enter status "+user.name
24-
title = raw_input()
22+
print ("Enter pic path "+user.name)
23+
pic = os.path.abspath(input())
24+
print ("Enter status "+user.name)
25+
title = input()
2526
api.update_with_media(pic, status=title)
2627

27-
print "\n\nDONE!!"
28+
print ("\n\nDONE!!")
2829

2930
def initialize():
3031
global api, auth, user
@@ -40,14 +41,14 @@ def initialize():
4041
user = api.me()
4142

4243
def main():
43-
doit = int(raw_input("\n1. text\n2. picture\n"))
44+
doit = int(input("\n1. text\n2. picture\n"))
4445
initialize()
4546
if doit == 1:
4647
tweetthis("text")
4748
elif doit == 2:
4849
tweetthis("pic")
4950
else:
50-
print "OK, Let's try again!"
51+
print ("OK, Let's try again!")
5152
main()
5253

5354
main()

code/Math/MathGame.py

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
"""
2-
This program is a Math Game with 3 levels and grading system accordingly.
3-
Questions have 2 operands and 1 operator.
4-
Teaches use of random module in Python.
5-
Written in Python 2.7
6-
written by: shreydan github.com/shreydan
7-
"""
2+
written in Python 3 by Shreyas Daniel - github.com/shreydan
3+
Game: 2 operators, 2 operands, 3 levels and grades accordingly.
4+
5+
***********************************************
6+
* READ THIS CAREFULLY TO UNDERSTAND THE LOGIC *
7+
***********************************************
88
9+
"""
910

1011
import random
1112

1213
correct = 0
1314
wrong = 0
1415

1516
def result(correct, wrong, level):
16-
print "You got %s correct and %s wrong!"%(correct,wrong)
17+
print ("You got %s correct and %s wrong!"%(correct,wrong))
1718
if level == 1:
1819
if correct < 5:
19-
print "Grade: C"
20+
print ("Grade: C")
2021
elif correct >= 5 and correct <= 7:
21-
print "Grade: B"
22+
print ("Grade: B")
2223
else:
23-
print "Grade: A"
24+
print ("Grade: A")
2425

2526
if level == 2:
2627
if correct <7:
27-
print "Grade: C"
28+
print "Grade: C")
2829
elif correct >= 7 and correct <= 15:
29-
print "Grade: B"
30+
print ("Grade: B")
3031
else:
31-
print "Grade: A"
32+
print ("Grade: A")
3233

3334
if level == 3:
3435
if correct < 13:
35-
print "Grade: C"
36+
print ("Grade: C")
3637
elif correct >= 13 and correct <= 19 :
37-
print "Grade: B"
38+
print ("Grade: B")
3839
else:
39-
print "Grade: A"
40+
print ("Grade: A")
4041

4142
def finalizer(level,questions,correct,wrong):
4243
if level == 1 and questions == 10:
@@ -55,13 +56,13 @@ def calculator(numbers, operator, level, questions):
5556
elif operator == '*':
5657
answer = float(numbers[0] * numbers[1])
5758

58-
guess = float(raw_input("\n\n" + str(numbers[0]) + " "+operator+" " + str(numbers[1]) + "\n"))
59+
guess = float(input("\n\n" + str(numbers[0]) + " "+operator+" " + str(numbers[1]) + "\n"))
5960
global correct, wrong
6061
if guess == answer:
6162
correct += 1
6263
else:
6364
wrong += 1
64-
print "\nCorrect answer: %s"%answer
65+
print ("\nCorrect answer: %s"%answer)
6566

6667
finalizer(level,questions,correct,wrong)
6768

@@ -72,13 +73,15 @@ def levels(level,questions):
7273

7374
global numbers
7475
numbers=[]
75-
while len(numbers) <= 1:
76-
if level==1:
77-
numbers.append(float(random.randint(1,15)))
78-
elif level==2:
79-
numbers.append(float(random.randint(5,20)))
80-
elif level==3:
81-
numbers.append(float(random.randint(10,30)))
76+
if level==1:
77+
while len(numbers) <= 1:
78+
numbers.append(float(random.randint(1,15)))
79+
elif level==2:
80+
while len(numbers) <= 1:
81+
numbers.append(float(random.randint(5,20)))
82+
elif level==3:
83+
while len(numbers) <= 1:
84+
numbers.append(float(random.randint(10,30)))
8285

8386
calculator(numbers,operator,level,questions)
8487

@@ -98,7 +101,7 @@ def loop(level):
98101
questions+= 1
99102

100103
def difficultyselector():
101-
level = int(raw_input("1. Easy\n2.Medium\n3. Hard\n\n"))
104+
level = int(input("1. Easy\n2.Medium\n3. Hard\n\n"))
102105
if level==1:
103106
loop(level)
104107
elif level==2:
@@ -107,19 +110,7 @@ def difficultyselector():
107110
loop(level)
108111

109112
def welcome():
110-
print "The Math Game\n"
113+
print ("The Math Game\nCoded with <3 by Shreyas Daniel\n2016\n")
111114
difficultyselector()
112115

113116
welcome()
114-
115-
116-
"""
117-
Working:
118-
-> welcome(): main method, does what it says!
119-
-> difficultyselector(): selects level
120-
-> loop(level): a question looper based on your level from difficultyselector()
121-
-> levels(level, questions): generates operator and operands
122-
-> calculator(numbers,operator,level,questions): calculates the answer, increments right and wrong answers and prints wrong ones.
123-
-> finalizer(level,questions,correct,wrong): evaluates solutions and sends them for result
124-
-> result(correct, wrong, level): prints grade accordingly.
125-
"""

code/Math/Primes/primes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Written in Python 2.7
2+
Written in Python 3
33
44
Description: writes "n" prime nos to a file.
55
teaches while loop, defining function and calling it, file input.
@@ -16,16 +16,16 @@ def write_to_file(primes):
1616
pnos = str(pnos)+"\n"
1717
f.write(pnos)
1818

19-
print "The primes are in the file primes.txt"
19+
print ("The primes are in the file primes.txt")
2020

2121

2222
def prime():
2323

2424
primes = []
2525
i = 1
2626
num = 2
27-
n = int(raw_input("Enter the no. of prime nos. you want\n>>> "))
28-
print "generating..."
27+
n = int(input("Enter the no. of prime nos. you want\n>>> "))
28+
print ("generating...")
2929
while len(primes) < n: # loop to generate n prime nos.
3030
count = 0
3131
i = 1

code/Math/collatz.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Written in Python 2.
2+
Written in Python 3.
33
44
This program is all yours now! Have fun experimenting!!
55
@@ -23,13 +23,13 @@ def collatz(n): # collatz function with n as parameter.
2323
step += 1
2424
break
2525

26-
print "It took %s steps to reach 1 with %s"%(step,num)
26+
print ("It took %s steps to reach 1 with %s"%(step,num))
2727

2828
def input():
2929
# takes input and rejects it to use it as an argument till it's neither 1 nor 0.
30-
n= int(raw_input("Enter a no. "))
30+
n= int(input("Enter a no. "))
3131
while n==1 or n == 0:
32-
print "Nope, Another.."
32+
print ("Nope, Another..")
3333
input()
3434
else:
3535
collatz(n) # call collatz function with n as argument

code/Python Modules/checknet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
22
program to check internet connection
3-
written in: Python 2.7
3+
written in: Python 3
44
written by: Shreyas Daniel github.com/shreydan
55
"""
66

77
import urllib2
88

99
try:
1010
urllib2.urlopen("https://www.google.com")
11-
print "Internet is working..."
11+
print ("Internet is working...")
1212
except urllib2.URLError:
13-
print "Internet is not working..."
13+
print ("Internet is not working...")
1414

code/Selenium/Google Search/imfeelinglucky.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
22
I'm Feeling Lucky using Selenium module: pip install selenium. Ignore if installed from requirements.txt
3-
written in Python 2.7
3+
written in Python 3
44
55
Uses Firefox webdriver, feel free to change the browser variable with desired driver
66
77
"""
88
from selenium import webdriver
99

10-
search = raw_input("Enter search:\n>>>")
10+
search = input("Enter search:\n>>>")
1111
search = search.replace(" ","+")
1212
url = "https://www.google.com/search?q="+search
1313

code/Selenium/Google Search/search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""
22
Google search using Selenium module: pip install selenium. Ignore if installed from requirements.txt
3-
written in Python 2.7
3+
written in Python 3
44
55
Uses Firefox webdriver, feel free to change the browser variable with desired driver
66
77
"""
88

99
from selenium import webdriver
1010

11-
search = raw_input("Enter your search:\n>>>")
11+
search = input("Enter your search:\n>>>")
1212
search = search.replace(" ","+")
1313
url = "https://www.google.com/search?q="+search
1414

code/Selenium/Instagram Instant Follow/instafollow.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
"""
2-
Instagram Instant follow using Selenium module: pip install selenium
3-
written in Python 2.7
42
5-
Uses Firefox webdriver, feel free to change the browser variable with desired driver
3+
written in Python 3 by Shreyas Daniel - github.com/shreydan
4+
5+
follow people on Instagram by providing usernames to the program
6+
requirements: Selenium -> pip install selenium
7+
no exceptions are catched in this version yet.
8+
Instagram account can't have 2 factor verification.
9+
610
"""
711

812
from selenium import webdriver
913
from selenium.webdriver.common.keys import Keys
1014
import time
1115

1216
def done():
13-
print "Followed all the users"
17+
print ("Followed all the users")
1418
time.sleep(2)
1519
browser.quit()
1620

@@ -20,7 +24,7 @@ def follow(userlist):
2024
browser.get(url)
2125
follow_btn = browser.find_element_by_class_name("_ah57t")
2226
follow_btn.click()
23-
print "Followed: "+users
27+
print ("Followed: "+users)
2428
time.sleep(2)
2529

2630
done()
@@ -29,16 +33,19 @@ def follow(userlist):
2933
def users():
3034
time.sleep(3)
3135
userlist = []
32-
n = int(raw_input("Enter no. of users to follow "))
33-
for i in range(0,n):
34-
follow_user = raw_input("Enter correct username ")
35-
userlist.append(follow_user)
36-
follow(userlist)
36+
n = int(input("Enter no. of users to follow "))
37+
if n == 0:
38+
done()
39+
else:
40+
for i in range(0,n):
41+
follow_user = input("Enter correct username ")
42+
userlist.append(follow_user)
43+
follow(userlist)
3744

3845
def login():
3946
global usr
40-
usr = raw_input("Enter your username ")
41-
psw = raw_input("Enter your password ")
47+
usr = input("Enter your username ")
48+
psw = input("Enter your password ")
4249
username = browser.find_element_by_name("username")
4350
username.send_keys(usr)
4451
password = browser.find_element_by_name("password")

code/Strings/charfreqcount.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Written in Python 2.
2+
Written in Python 3.
33
44
This program is all yours now! Have fun experimenting!!
55
@@ -9,7 +9,7 @@
99
"""
1010

1111
def main():
12-
sentence = raw_input("\n\nEnter a sentence\n")
12+
sentence = input("\n\nEnter a sentence\n")
1313
sentence = sentence.lower()
1414
string = sentence.replace(" ","")
1515
chars = []
@@ -30,10 +30,10 @@ def main():
3030
count += 1
3131
alphad.update({abet:count})
3232

33-
print "\n<!---FREQUENCY---!>\n"
33+
print ("\n<!---FREQUENCY---!>\n")
3434
for ch in alphad:
35-
print ch + " : "+str(alphad[ch])
36-
print "\n\n"
35+
print (ch + " : "+str(alphad[ch]))
36+
print ("\n\n")
3737

3838

3939
main()

0 commit comments

Comments
 (0)