Skip to content

Commit a5bd693

Browse files
committed
modify
1 parent 38167eb commit a5bd693

16 files changed

+237
-236
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Taking kilometers input from the user
2-
kilometers = float(input("Enter value in kilometers: "))
3-
4-
# conversion factor
5-
conv_fac = 0.621371
6-
7-
# calculate miles
8-
miles = kilometers * conv_fac
1+
# Taking kilometers input from the user
2+
kilometers = float(input("Enter value in kilometers: "))
3+
4+
# conversion factor
5+
conv_fac = 0.621371
6+
7+
# calculate miles
8+
miles = kilometers * conv_fac
99
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
""" Currency Converter
2-
----------------------------------------
3-
"""
4-
import urllib.request
5-
import json
6-
def currency_converter(currency_from, currency_to, currency_input):
7-
yql_base_url = "https://query.yahooapis.com/v1/public/yql"
8-
yql_query = 'select%20*%20from%20yahoo.finance.xchange%20where%20pair' \
9-
'%20in%20("'+currency_from+currency_to+'")'
10-
yql_query_url = yql_base_url + "?q=" + yql_query + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
11-
try:
12-
yql_response = urllib.request.urlopen(yql_query_url)
13-
try:
14-
json_string = str(yql_response.read())
15-
json_string = json_string[2:
16-
json_string = json_string[:-1]
17-
print(json_string)
18-
yql_json = json.loads(json_string)
19-
last_rate = yql_json['query']['results']['rate']['Rate']
20-
currency_output = currency_input * float(last_rate)
21-
return currency_output
22-
except (ValueError, KeyError, TypeError):
23-
print(yql_query_url)
24-
return "JSON format error"
25-
except IOError as e:
26-
print(str(e))
27-
currency_input = 1
28-
// currency codes : http://en.wikipedia.org/wiki/ISO_4217
29-
currency_from = "USD"
30-
currency_to = "TRY"
31-
rate = currency_converter(currency_from, currency_to, currency_input)
1+
""" Currency Converter
2+
----------------------------------------
3+
"""
4+
import urllib.request
5+
import json
6+
def currency_converter(currency_from, currency_to, currency_input):
7+
yql_base_url = "https://query.yahooapis.com/v1/public/yql"
8+
yql_query = 'select%20*%20from%20yahoo.finance.xchange%20where%20pair' \
9+
'%20in%20("'+currency_from+currency_to+'")'
10+
yql_query_url = yql_base_url + "?q=" + yql_query + "&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
11+
try:
12+
yql_response = urllib.request.urlopen(yql_query_url)
13+
try:
14+
json_string = str(yql_response.read())
15+
json_string = json_string[2:
16+
json_string = json_string[:-1]
17+
print(json_string)
18+
yql_json = json.loads(json_string)
19+
last_rate = yql_json['query']['results']['rate']['Rate']
20+
currency_output = currency_input * float(last_rate)
21+
return currency_output
22+
except (ValueError, KeyError, TypeError):
23+
print(yql_query_url)
24+
return "JSON format error"
25+
except IOError as e:
26+
print(str(e))
27+
currency_input = 1
28+
// currency codes : http://en.wikipedia.org/wiki/ISO_4217
29+
currency_from = "USD"
30+
currency_to = "TRY"
31+
rate = currency_converter(currency_from, currency_to, currency_input)
3232
print(rate)
Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
""" Instagram Photo Downloader
2-
----------------------------------------
3-
"""
4-
from sys import argv
5-
import urllib
6-
from bs4 import BeautifulSoup
7-
import datetime
8-
def ShowHelp():
9-
print 'Insta Image Downloader'
10-
print ''
11-
print 'Usage:'
12-
print 'insta.py [OPTION] [URL]'
13-
print ''
14-
print 'Options:'
15-
print '-u [Instagram URL]\tDownload single photo from Instagram URL'
16-
print '-f [File path]\t\tDownload Instagram photo(s) using file list'
17-
print '-h, --help\t\tShow this help message'
18-
print ''
19-
print 'Example:'
20-
print 'python insta.py -u https://instagram.com/p/xxxxx'
21-
print 'python insta.py -f /home/username/filelist.txt'
22-
print ''
23-
exit()
24-
def DownloadSingleFile(fileURL):
25-
print 'Downloading image...'
26-
f = urllib.urlopen(fileURL)
27-
htmlSource = f.read()
28-
soup = BeautifulSoup(htmlSource,'html.parser')
29-
metaTag = soup.find_all('meta', {'property':'og:image'})
30-
imgURL = metaTag[0]['content']
31-
fileName = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S") + '.jpg'
32-
urllib.urlretrieve(imgURL, fileName)
33-
print 'Done. Image saved to disk as ' + fileName
34-
if __name__ == '__main__':
35-
if len(argv) == 1:
36-
ShowHelp()
37-
if argv[1] in ('-h', '--help'):
38-
ShowHelp()
39-
elif argv[1] == '-u':
40-
instagramURL = argv[2]
41-
DownloadSingleFile(instagramURL)
42-
elif argv[1] == '-f':
43-
filePath = argv[2]
44-
f = open(filePath)
45-
line = f.readline()
46-
while line:
47-
instagramURL = line.rstrip('\n')
48-
DownloadSingleFile(instagramURL)
49-
line = f.readline()
1+
""" Instagram Photo Downloader
2+
----------------------------------------
3+
"""
4+
from sys import argv
5+
import urllib
6+
from bs4 import BeautifulSoup
7+
import datetime
8+
def ShowHelp():
9+
print 'Insta Image Downloader'
10+
print ''
11+
print 'Usage:'
12+
print 'insta.py [OPTION] [URL]'
13+
print ''
14+
print 'Options:'
15+
print '-u [Instagram URL]\tDownload single photo from Instagram URL'
16+
print '-f [File path]\t\tDownload Instagram photo(s) using file list'
17+
print '-h, --help\t\tShow this help message'
18+
print ''
19+
print 'Example:'
20+
print 'python insta.py -u https://instagram.com/p/xxxxx'
21+
print 'python insta.py -f /home/username/filelist.txt'
22+
print ''
23+
exit()
24+
def DownloadSingleFile(fileURL):
25+
print 'Downloading image...'
26+
f = urllib.urlopen(fileURL)
27+
htmlSource = f.read()
28+
soup = BeautifulSoup(htmlSource,'html.parser')
29+
metaTag = soup.find_all('meta', {'property':'og:image'})
30+
imgURL = metaTag[0]['content']
31+
fileName = datetime.datetime.now().strftime("%Y-%m-%d_%H:%M:%S") + '.jpg'
32+
urllib.urlretrieve(imgURL, fileName)
33+
print 'Done. Image saved to disk as ' + fileName
34+
if __name__ == '__main__':
35+
if len(argv) == 1:
36+
ShowHelp()
37+
if argv[1] in ('-h', '--help'):
38+
ShowHelp()
39+
elif argv[1] == '-u':
40+
instagramURL = argv[2]
41+
DownloadSingleFile(instagramURL)
42+
elif argv[1] == '-f':
43+
filePath = argv[2]
44+
f = open(filePath)
45+
line = f.readline()
46+
while line:
47+
instagramURL = line.rstrip('\n')
48+
DownloadSingleFile(instagramURL)
49+
line = f.readline()
5050
f.close()
Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
1-
""" Number Guessing Game
2-
----------------------------------------
3-
"""
4-
import random
5-
attempts_list = []
6-
def show_score():
7-
if len(attempts_list) <= 0:
8-
print("There is currently no high score, it's yours for the taking!")
9-
else:
10-
print("The current high score is {} attempts".format(min(attempts_list)))
11-
def start_game():
12-
random_number = int(random.randint(1, 10))
13-
print("Hello traveler! Welcome to the game of guesses!")
14-
player_name = input("What is your name? ")
15-
wanna_play = input("Hi, {}, would you like to play the guessing game? (Enter Yes/No) ".format(player_name))
16-
// Where the show_score function USED to be
17-
attempts = 0
18-
show_score()
19-
while wanna_play.lower() == "yes":
20-
try:
21-
guess = input("Pick a number between 1 and 10 ")
22-
if int(guess) < 1 or int(guess) > 10:
23-
raise ValueError("Please guess a number within the given range")
24-
if int(guess) == random_number:
25-
print("Nice! You got it!")
26-
attempts += 1
27-
attempts_list.append(attempts)
28-
print("It took you {} attempts".format(attempts))
29-
play_again = input("Would you like to play again? (Enter Yes/No) ")
30-
attempts = 0
31-
show_score()
32-
random_number = int(random.randint(1, 10))
33-
if play_again.lower() == "no":
34-
print("That's cool, have a good one!")
35-
break
36-
elif int(guess) > random_number:
37-
print("It's lower")
38-
attempts += 1
39-
elif int(guess) < random_number:
40-
print("It's higher")
41-
attempts += 1
42-
except ValueError as err:
43-
print("Oh no!, that is not a valid value. Try again...")
44-
print("({})".format(err))
45-
else:
46-
print("That's cool, have a good one!")
47-
if __name__ == '__main__':
1+
""" Number Guessing Game
2+
----------------------------------------
3+
"""
4+
import random
5+
attempts_list = []
6+
def show_score():
7+
if len(attempts_list) <= 0:
8+
print("There is currently no high score, it's yours for the taking!")
9+
else:
10+
print("The current high score is {} attempts".format(min(attempts_list)))
11+
def start_game():
12+
random_number = int(random.randint(1, 10))
13+
print("Hello traveler! Welcome to the game of guesses!")
14+
player_name = input("What is your name? ")
15+
wanna_play = input("Hi, {}, would you like to play the guessing game? (Enter Yes/No) ".format(player_name))
16+
// Where the show_score function USED to be
17+
attempts = 0
18+
show_score()
19+
while wanna_play.lower() == "yes":
20+
try:
21+
guess = input("Pick a number between 1 and 10 ")
22+
if int(guess) < 1 or int(guess) > 10:
23+
raise ValueError("Please guess a number within the given range")
24+
if int(guess) == random_number:
25+
print("Nice! You got it!")
26+
attempts += 1
27+
attempts_list.append(attempts)
28+
print("It took you {} attempts".format(attempts))
29+
play_again = input("Would you like to play again? (Enter Yes/No) ")
30+
attempts = 0
31+
show_score()
32+
random_number = int(random.randint(1, 10))
33+
if play_again.lower() == "no":
34+
print("That's cool, have a good one!")
35+
break
36+
elif int(guess) > random_number:
37+
print("It's lower")
38+
attempts += 1
39+
elif int(guess) < random_number:
40+
print("It's higher")
41+
attempts += 1
42+
except ValueError as err:
43+
print("Oh no!, that is not a valid value. Try again...")
44+
print("({})".format(err))
45+
else:
46+
print("That's cool, have a good one!")
47+
if __name__ == '__main__':
4848
start_game()
Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
""" Rock Paper Scissors
2-
----------------------------------------
3-
"""
4-
import random
5-
import os
6-
import re
7-
os.system('cls' if os.name=='nt' else 'clear')
8-
while (1 < 2):
9-
print "\n"
10-
print "Rock, Paper, Scissors - Shoot!"
11-
userChoice = raw_input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ")
12-
if not re.match("[SsRrPp]", userChoice):
13-
print "Please choose a letter:"
14-
print "[R]ock, [S]cissors or [P]aper."
15-
continue
16-
// Echo the user's choice
17-
print "You chose: " + userChoice
18-
choices = ['R', 'P', 'S']
19-
opponenetChoice = random.choice(choices)
20-
print "I chose: " + opponenetChoice
21-
if opponenetChoice == str.upper(userChoice):
22-
print "Tie! "
23-
#if opponenetChoice == str("R") and str.upper(userChoice) == "P"
24-
elif opponenetChoice == 'R' and userChoice.upper() == 'S':
25-
print "Scissors beats rock, I win! "
26-
continue
27-
elif opponenetChoice == 'S' and userChoice.upper() == 'P':
28-
print "Scissors beats paper! I win! "
29-
continue
30-
elif opponenetChoice == 'P' and userChoice.upper() == 'R':
31-
print "Paper beat rock, I win! "
32-
continue
33-
else:
1+
""" Rock Paper Scissors
2+
----------------------------------------
3+
"""
4+
import random
5+
import os
6+
import re
7+
os.system('cls' if os.name=='nt' else 'clear')
8+
while (1 < 2):
9+
print "\n"
10+
print "Rock, Paper, Scissors - Shoot!"
11+
userChoice = raw_input("Choose your weapon [R]ock], [P]aper, or [S]cissors: ")
12+
if not re.match("[SsRrPp]", userChoice):
13+
print "Please choose a letter:"
14+
print "[R]ock, [S]cissors or [P]aper."
15+
continue
16+
// Echo the user's choice
17+
print "You chose: " + userChoice
18+
choices = ['R', 'P', 'S']
19+
opponenetChoice = random.choice(choices)
20+
print "I chose: " + opponenetChoice
21+
if opponenetChoice == str.upper(userChoice):
22+
print "Tie! "
23+
#if opponenetChoice == str("R") and str.upper(userChoice) == "P"
24+
elif opponenetChoice == 'R' and userChoice.upper() == 'S':
25+
print "Scissors beats rock, I win! "
26+
continue
27+
elif opponenetChoice == 'S' and userChoice.upper() == 'P':
28+
print "Scissors beats paper! I win! "
29+
continue
30+
elif opponenetChoice == 'P' and userChoice.upper() == 'R':
31+
print "Paper beat rock, I win! "
32+
continue
33+
else:
3434
print "You win!"
File renamed without changes.

0 commit comments

Comments
 (0)