Skip to content

Commit 0898393

Browse files
committed
Merge branch 'geekcomputers/master'
2 parents 916e5ff + 7bd4c59 commit 0898393

4 files changed

Lines changed: 91 additions & 62 deletions

File tree

Print_List_of_Even_Numbers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
print list(x for x in range(2,100,2))
1+
print [x for x in range(2, 100) if not x % 2]
2+
print range(2, 100, 2)

check_file.py

Lines changed: 61 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,61 @@
1-
# Script Name : check_file.py
2-
3-
# Author : Craig Richards
4-
# Created : 20 May 2013
5-
# Last Modified :
6-
# Version : 1.0
7-
8-
# Modifications : with statement added to ensure correct file closure
9-
10-
# Description : Check a file exists and that we can read the file
11-
from __future__ import print_function
12-
import sys # Import the Modules
13-
import os # Import the Modules
14-
15-
# Prints usage if not appropriate length of arguments are provided
16-
def usage():
17-
print('[-] Usage: python check_file.py <filename1> [filename2] ... [filenameN]')
18-
exit(0)
19-
20-
21-
# Readfile Functions which open the file that is passed to the script
22-
def readfile(filename):
23-
with open(filename, 'r') as f: # Ensure file is correctly closed under all circumstances
24-
file = f.read()
25-
print(file)
26-
27-
def main():
28-
if len(sys.argv) >= 2: # Check the arguments passed to the script
29-
filenames = sys.argv[1:]
30-
for filename in filenames: # Iterate for each filename passed in command line argument
31-
if not os.path.isfile(filename): # Check the File exists
32-
print ('[-] ' + filename + ' does not exist.')
33-
filenames.remove(filename) #remove non existing files from filenames list
34-
continue
35-
36-
if not os.access(filename, os.R_OK): # Check you can read the file
37-
print ('[-] ' + filename + ' access denied')
38-
filenames.remove(filename) # remove non readable filenames
39-
continue
40-
else:
41-
usage() # Print usage if not all parameters passed/Checked
42-
43-
# Read the content of each file
44-
for filename in filenames:
45-
print ('[+] Reading from : ' + filename) # Display Message and read the file contents
46-
readfile(filename)
47-
48-
if __name__ == '__main__':
49-
main()
1+
# Script Name : check_file.py
2+
3+
# Author : Craig Richards
4+
# Created : 20 May 2013
5+
# Last Modified :
6+
# Version : 1.0
7+
8+
# Modifications : with statement added to ensure correct file closure
9+
10+
# Description : Check a file exists and that we can read the file
11+
from __future__ import print_function
12+
import sys # Import the Modules
13+
import os # Import the Modules
14+
15+
# Prints usage if not appropriate length of arguments are provided
16+
17+
18+
def usage():
19+
print('[-] Usage: python check_file.py [filename1] [filename2] ... [filenameN]')
20+
21+
22+
# Readfile Functions which open the file that is passed to the script
23+
def readfile(filename):
24+
with open(filename, 'r') as f: # Ensure file is correctly closed under
25+
file = f.read() # all circumstances
26+
print(file)
27+
print()
28+
print('#'*80)
29+
print()
30+
31+
def main():
32+
# Check the arguments passed to the script
33+
if len(sys.argv) >= 2:
34+
filenames = sys.argv[1:]
35+
36+
# Iterate for each filename passed in command line argument
37+
for filename in filenames:
38+
if not os.path.isfile(filename): # Check the File exists
39+
print('[-] ' + filename + ' does not exist.')
40+
filenames.remove(filename) #remove non existing files from fileNames list
41+
continue
42+
43+
# Check you can read the file
44+
if not os.access(filename, os.R_OK):
45+
print('[-] ' + filename + ' access denied')
46+
# remove non readable fileNames
47+
filenames.remove(filename)
48+
continue
49+
50+
# Read the content of each file
51+
for filename in filenames:
52+
# Display Message and read the file contents
53+
print('[+] Reading from : ' + filename)
54+
readfile(filename)
55+
56+
else:
57+
usage() # Print usage if not all parameters passed/Checked
58+
59+
60+
if __name__ == '__main__':
61+
main()

dice_rolling_simulator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
#Checking the user input to start the program.
1515
while correct_word == False:
1616

17-
user_input_raw = raw_input("\r\nWelcome to the Dice Rolling Simulator! We currently support 6, 8, and 12 sided die! Type [start] to begin!\r\n?>")
17+
user_input_raw = raw_input("\r\nWelcome to the Dice Rolling Simulator! We currently support 6, 8, and 12 sided die! \
18+
Type [start] to begin!\r\n?>")
1819

1920
#Converting the user input to lower case.
2021
user_input = (user_input_raw.lower())
@@ -46,7 +47,8 @@
4647
else:
4748
print "\r\nPlease choose one of the applicable options!\r\n"
4849

49-
#Another inner while loop. This one does the actual rolling, as well as allowing the user to re-roll without restarting the program.
50+
#Another inner while loop. This one does the actual rolling, as well as
51+
#allowing the user to re-roll without restarting the program.
5052
while dicer == False:
5153

5254
if user_dice_chooser == 6:

dir_test.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@
77

88
# Description : Tests to see if the directory testdir exists, if not it will create the directory for you
99
from __future__ import print_function
10-
import os #Import the OS Module
11-
CheckDir = raw_input("Enter the name of the directory to check : ")
12-
print
13-
if os.path.exists(CheckDir):#Checks if the dir exists
14-
print("The directory exists")
15-
else:
16-
print("No directory found for "+CheckDir) #Output if no directory
17-
print
18-
os.makedirs(CheckDir)#Creates a new dir for the given name
19-
print("Directory created for "+CheckDir)
10+
import os # Import the OS Module
11+
import sys
12+
13+
14+
def main():
15+
if sys.version_info.major >= 3: # if the interpreter version is 3.X, use 'input',
16+
input_func = input # otherwise use 'raw_input'
17+
else:
18+
input_func = raw_input
19+
20+
CheckDir = input_func("Enter the name of the directory to check : ")
21+
print()
22+
23+
if os.path.exists(CheckDir): # Checks if the dir exists
24+
print("The directory exists")
25+
else:
26+
print("No directory found for " + CheckDir) # Output if no directory
27+
print()
28+
os.makedirs(CheckDir) # Creates a new dir for the given name
29+
print("Directory created for " + CheckDir)
30+
31+
32+
if __name__ == '__main__':
33+
main()

0 commit comments

Comments
 (0)