<file_sep>#  exercise_1

line = input('Enter accepted price: ')
filepath = input('Enter filename : ')

file = open(filepath, 'w+')
file.write(line)
file.close()

#  exercise_2

line = input('Enter accepted price: ')
filepath = input('Enter filename : ')

try:
    file = open(filepath, 'w+')
    file.write(line)
    file.close()
except:
    print('SORRY WE HAVE AN ERROR. PLEASE TRY AGAIN')

#  exercise_3

line = input('Enter accepted price: ')
filepath = input('Enter filename : ')

try:
    file = open(filepath, 'w+')
    file.write(line)
    file.close()
except FileNotFoundError as e:
    print('Error opening file', filepath, e)
except:
    print('SORRY WE HAVE AN ERROR. PLEASE TRY AGAIN')

#  exercise_4

line = input('Enter accepted price: ')
filepath = input('Enter filename : ')

try:
    file = open(filepath, 'w+')
    file.write(line)
    value = int(line)
    file.close()
    print('The value saved in file is', value)
except FileNotFoundError as e:
    print('Error opening file', filepath, e)
except:
    print('SORRY WE HAVE AN ERROR. PLEASE TRY AGAIN')


#  exercise_5

line = input('Enter accepted price: ')
filepath = input('Enter filename : ')

try:
    file = open(filepath, 'w+')
    file.write(line)
    file.close()
    value = int(line)
    print('The value saved in file is', value)
except FileNotFoundError as e:
    print('Error opening file', filepath, e)
except ValueError as e:
    print('The value entered cannot be converted to a number', line, e)
except:
    print('SORRY WE HAVE AN ERROR. PLEASE TRY AGAIN')
else:
    print('Actions completed successfully')<file_sep>import os
import time

print("Current directory is:", os.getcwd())

current_dir = os.getcwd()
filename = "results.txt"
fullpath = os.path.join(current_dir, filename)
print("\nThe constructed file path is: ", fullpath)

relative_path = "output.txt"
print("\nThe absolute path is: ", os.path.abspath(relative_path))

filepath = r"c:\temp\results.txt"
print("\nThe file name part is: ", os.path.basename(filepath))

print("\nIs file existing? ", os.path.exists(filepath))

if os.path.exists(filepath):
    print("\nLast modify date is: ", os.path.getmtime(filepath))
    print("Last modify date is: ", time.localtime(os.path.getmtime(filepath)))

    print("\nFile size is: ", os.path.getsize(filepath))

    print("\nIs it a file?", os.path.isfile(filepath))
    print("Is it a dir? ", os.path.isdir(filepath))

    print("\nPath splitted: ", os.path.split(filepath))
    print("Only file name part: ", os.path.split(filepath)[1])

    print("\nPath splitted into drive: ", os.path.splitdrive(filepath))
    print("Only drive: ", os.path.splitdrive(filepath)[0])



<file_sep>import os
import time

dir = input("Enter directory name: ")

if not os.path.isdir(dir):
    print(f"{dir} must be a directory")

else:
    file = input(f"Enter filename saved in directory {dir}: ")

    path = os.path.join(dir, file)

    if not os.path.isfile(path):
        print(f"{path} file does't exist!")

    else:
        print(f"displaying properties of file {path}")
        print("Last modify date is: ", time.localtime(os.path.getmtime(path)))
        print('Size in bytes', os.path.getsize(path))
        print('Current directory is: ', os.getcwd())
        print('Relative path to the file is', os.path.relpath(path))
<file_sep>def check_int(s):
    if s[0] in ('-', '+'):
        return s[1:].isdigit()
    return s.isdigit()


print('This program solves equation ax^2+bx+c = 0')
print('Enter the values for a, b and c:')

a = input("a = ")
b = input("b = ")
c = input("c = ")

if not (check_int(a) and check_int(b) and check_int(c)):
    print("a, b and c need to be int!")

else:
    a = int(a)
    b = int(b)
    c = int(c)

    if a == 0:
        print("a cannot be a 0!")
    else:
        delta = b**2 - 4*a*c

        if delta < 0:
            print("there is no solution")
        elif delta == 0:
            x1 = -b/(2*a)
            print(f"there is one solution: {x1}")
        else:
            x1 = (-b-delta**0.5)/(2*a)
            x2 = (-b+delta**0.5)/(2*a)
            print(f"there are two solutions: {x1} and {x2}")
<file_sep>filesize = input("Enter the max file size (MB): ")
filesize = int(filesize)
print(f"The max size is {filesize}")
print(f"Size in KB is {filesize * 1024}")<file_sep>class Cake:

    def __init__(self, name, kind, taste, additives, filling):
        self.name = name
        self.kind = kind
        self.taste = taste
        self.additives = additives.copy()
        self.filling = filling


cake01 = Cake('Vanilla Cake', 'cake', 'vanilla', ['chocolade', 'nuts'], 'cream')
cake02 = Cake('Chocolade Muffin', 'muffin', 'chocolade', ['chocolade'], '')
cake03 = Cake('Super Sweet Maringue', 'meringue', 'very sweet', [], '')

bakery_offer = []
bakery_offer.append(cake01)
bakery_offer.append(cake02)
bakery_offer.append(cake03)

print("Today in our offer:")
for c in bakery_offer:
    print("{} - ({}) main taste: {} with additives of {}, filled with {}".format(
        c.name, c.kind, c.taste, c.additives, c.filling))