This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def parent_directory(): | |
# Create a relative path to the parent | |
# of the current working directory | |
relative_parent = os.path.join(os.getcwd(), os.pardir) | |
# Return the absolute path of the parent directory | |
return os.path.abspath(relative_parent) | |
print(parent_directory()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import datetime | |
def file_date(filename): | |
# Create the file in the current directory | |
with open (filename,'w') as file: | |
pass | |
timestamp = os.path.getmtime(filename) | |
c=datetime.datetime.fromtimestamp(timestamp) | |
# Convert the timestamp into a readable format, then into a string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def new_directory(directory, filename): | |
# Before creating a new directory, check to see if it already exists | |
if not os.path.exists(directory): | |
os.mkdir(directory) | |
name=os.path.join(directory, filename) | |
file=open(name,'w') | |
file.close() | |
return os.listdir(directory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def octal_to_string(octal): | |
result = "" | |
value_letters = [(4,"r"),(2,"w"),(1,"x")] | |
#Iterating over each digit in octal | |
for digit in [int(n) for n in str(octal)]: | |
#Checking for each of permission values | |
for value, letter in value_letters: | |
if digit >= value: | |
result += letter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def replace_ending(sentence, old, new): | |
# Check if the old string is at the end of the sentence | |
if sentence.endswith(old): | |
# Using i as the slicing index, combine the part | |
# of the sentence up to the matched string at the | |
# end with the new string | |
i = sentence.split() | |
k =i[-1].replace(old,new) | |
new_sentence=sentence[0:-len(old)]+k | |
return new_sentence |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initials(phrase): | |
words = phrase.split() | |
result = "" | |
for word in words: | |
x=list(word) | |
if x[0].isupper(): | |
result +=x[0] | |
elif x[0].islower(): | |
result +=x[0].upper() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import os | |
import random | |
import re | |
import sys | |
# Complete the compareTriplets function below. | |
def compareTriplets(a, b): | |
c=0 | |
d=0 |