Created
May 7, 2020 02:43
-
-
Save RabeyaMuna/b983294b9e9216faf8491de7433343f2 to your computer and use it in GitHub Desktop.
The parent_directory function returns the name of the directory that's located just above the current working directory. Remember that '..' is a relative path alias that means "go up to the parent directory". Fill in the gaps to complete this function.
This file contains hidden or 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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
please i'm very confused on how to do it and it is an assignment I have to submit
menu = {
1: {"name": 'espresso',
"price": 1.99},
2: {"name": 'coffee',
"price": 2.50},
3: {"name": 'cake',
"price": 2.79},
4: {"name": 'soup',
"price": 4.50},
5: {"name": 'sandwich',
"price": 4.99}
}
def calculate_subtotal(order):
""" Calculates the subtotal of an order
def calculate_tax(subtotal):
""" Calculates the tax of an order
def summarize_order(order):
""" Summarizes the order
This function is provided for you, and will print out the items in an order
def print_order(order):
print('You have ordered ' + str(len(order)) + ' items')
items = []
items = [item["name"] for item in order]
print(items)
return order
This function is provided for you, and will display the menu
def display_menu():
print("------- Menu -------")
for selection in menu:
print(f"{selection}. {menu[selection]['name'] : <9} | {menu[selection]['price'] : >5}")
print()
This function is provided for you, and will create an order by prompting the user to select menu items
def take_order():
display_menu()
order = []
count = 1
for i in range(3):
item = input('Select menu item number ' + str(count) + ' (from 1 to 5): ')
count += 1
order.append(menu[int(item)])
return order
'''
Here are some sample function calls to help you test your implementations.
Feel free to change, uncomment, and add these as you wish.
'''
def main():
order = take_order()
print_order(order)
if name == "main":
main()
#2.)
def read_file(file_name):
""" Reads in a file.
def read_file_into_list(file_name):
""" Reads in a file and stores each line as an element in a list
def write_first_line_to_file(file_contents, output_filename):
""" Writes the first line of a string to a file.
def read_even_numbered_lines(file_name):
""" Reads in the even numbered lines of a file
def read_file_in_reverse(file_name):
""" Reads a file and returns a list of the lines in reverse order
'''
Here are some sample commands to help you run/test your implementations.
Feel free to uncomment/modify/add to them as you wish.
'''
def main():
file_contents = read_file("sampletext.txt")
# print(read_file_into_list("sampletext.txt"))
# write_first_line_to_file(file_contents, "online.txt")
# print(read_even_numbered_lines("sampletext.txt"))
# print(read_file_in_reverse("sampletext.txt"))
if name == "main":
main()