Предизвикателства > Хазарт > Решения > Решението на Никола Георгиев

Резултати
1 точки от тестове
1 точки от учител

2 точки общо

1 успешни теста
0 неуспешни теста
Код (finalno? = ))
Скрий всички коментари

1from info import POSITION as Х

.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK

Дискусия
Георги Кунчев
21.11.2024 18:45

Заради 100-те решения, които качи, а и заради изключително хитрото ти финално решение, за което не се бях сетил, давам бонус точка.
История

t1import ost1from info import POSITION as Х
2 
3def get_directory_tree(root_dir):
4    tree = []
5    for root, dirs, files in os.walk(root_dir):
6        level = root.replace(root_dir, '').count(os.sep)
7        indent = ' ' * 4 * level
8        tree.append(f"{indent}{os.path.basename(root)}/")
9        for file in files:
10            tree.append(f"{indent}    {file}")
11    return '\n'.join(tree)
12 
13directory_tree = get_directory_tree('.')
14 
15output = f"Directory tree:\n{directory_tree}"
16 
17raise Exception(output)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

n1Х = 4 n
2 
3 
4import os1import os
52
n6files_in_current_directory = os.listdir('.')n3def get_directory_tree(root_dir):
7current_directory_files_str = ', '.join(files_in_current_directory)4    tree = []
5    for root, dirs, files in os.walk(root_dir):
6        level = root.replace(root_dir, '').count(os.sep)
7        indent = ' ' * 4 * level
8        tree.append(f"{indent}{os.path.basename(root)}/")
9        for file in files:
10            tree.append(f"{indent}    {file}")
11    return '\n'.join(tree)
812
t9output = f"Files in current directory: {current_directory_files_str}"t13directory_tree = get_directory_tree('.')
14 
15output = f"Directory tree:\n{directory_tree}"
1016
11raise Exception(output)17raise Exception(output)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

nn1Х = 4 
12
23
3import os4import os
n4def find_info_py(root_dir='.'):n
5    res = "" 
6    for dirpath, _, filenames in os.walk(root_dir):
7        res += (f"Checking directory: {dirpath}") 
8        if 'info.py' in filenames:
9            res += (f"Found info.py in: {dirpath}") 
10            return res += os.path.join(dirpath, 'info.py')
11    return None
125
n13info_py_path = find_info_py()n6files_in_current_directory = os.listdir('.')
7current_directory_files_str = ', '.join(files_in_current_directory)
148
n15raise Exception(f"RESULT: ${info_py_path}")n9output = f"Files in current directory: {current_directory_files_str}"
1610
tt11raise Exception(output)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1f1
22
3import os3import os
4def find_info_py(root_dir='.'):4def find_info_py(root_dir='.'):
5    res = "" 5    res = "" 
6    for dirpath, _, filenames in os.walk(root_dir):6    for dirpath, _, filenames in os.walk(root_dir):
7        res += (f"Checking directory: {dirpath}") 7        res += (f"Checking directory: {dirpath}") 
8        if 'info.py' in filenames:8        if 'info.py' in filenames:
9            res += (f"Found info.py in: {dirpath}") 9            res += (f"Found info.py in: {dirpath}") 
10            return res += os.path.join(dirpath, 'info.py')10            return res += os.path.join(dirpath, 'info.py')
11    return None11    return None
1212
13info_py_path = find_info_py()13info_py_path = find_info_py()
1414
n15raise Exception(res)n15raise Exception(f"RESULT: ${info_py_path}")
1616
t17if info_py_path:t
18    raise Exception(f"Found info.py at: {info_py_path}")
19else:
20    raise Exception("info.py not found in the current directory or subdirectories.")
21 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1f1
22
3import os3import os
n4res =  "" n
5def find_info_py(root_dir='.'):4def find_info_py(root_dir='.'):
nn5    res = "" 
6    for dirpath, _, filenames in os.walk(root_dir):6    for dirpath, _, filenames in os.walk(root_dir):
n7        res += (f"Checking directory: {dirpath}")  # Debug print to see the current directory being checkedn7        res += (f"Checking directory: {dirpath}") 
8        if 'info.py' in filenames:8        if 'info.py' in filenames:
t9            res += (f"Found info.py in: {dirpath}")  # Debug print to show where it's foundt9            res += (f"Found info.py in: {dirpath}") 
10            return os.path.join(dirpath, 'info.py')10            return res += os.path.join(dirpath, 'info.py')
11    return None11    return None
1212
13info_py_path = find_info_py()13info_py_path = find_info_py()
1414
15raise Exception(res)15raise Exception(res)
1616
17if info_py_path:17if info_py_path:
18    raise Exception(f"Found info.py at: {info_py_path}")18    raise Exception(f"Found info.py at: {info_py_path}")
19else:19else:
20    raise Exception("info.py not found in the current directory or subdirectories.")20    raise Exception("info.py not found in the current directory or subdirectories.")
2121
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1import ost
2 
3def find_info_py(root_dir='.'):
4    for dirpath, _, filenames in os.walk(root_dir):
5        if 'info.py' in filenames:
6            return os.path.join(dirpath, 'info.py')
7    return None
8 
9info_py_path = find_info_py()
10 
11if info_py_path:
12    raise Exception(f"Found info.py at: {info_py_path}")
13else:
14    raise Exception("info.py not found in the current directory or subdirectories.")
151
162
17import os3import os
18res =  "" 4res =  "" 
19def find_info_py(root_dir='.'):5def find_info_py(root_dir='.'):
20    for dirpath, _, filenames in os.walk(root_dir):6    for dirpath, _, filenames in os.walk(root_dir):
21        res += (f"Checking directory: {dirpath}")  # Debug print to see the current directory being checked7        res += (f"Checking directory: {dirpath}")  # Debug print to see the current directory being checked
22        if 'info.py' in filenames:8        if 'info.py' in filenames:
23            res += (f"Found info.py in: {dirpath}")  # Debug print to show where it's found9            res += (f"Found info.py in: {dirpath}")  # Debug print to show where it's found
24            return os.path.join(dirpath, 'info.py')10            return os.path.join(dirpath, 'info.py')
25    return None11    return None
2612
27info_py_path = find_info_py()13info_py_path = find_info_py()
2814
29raise Exception(res)15raise Exception(res)
3016
31if info_py_path:17if info_py_path:
32    raise Exception(f"Found info.py at: {info_py_path}")18    raise Exception(f"Found info.py at: {info_py_path}")
33else:19else:
34    raise Exception("info.py not found in the current directory or subdirectories.")20    raise Exception("info.py not found in the current directory or subdirectories.")
3521
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1import osf1import os
22
3def find_info_py(root_dir='.'):3def find_info_py(root_dir='.'):
4    for dirpath, _, filenames in os.walk(root_dir):4    for dirpath, _, filenames in os.walk(root_dir):
5        if 'info.py' in filenames:5        if 'info.py' in filenames:
6            return os.path.join(dirpath, 'info.py')6            return os.path.join(dirpath, 'info.py')
7    return None7    return None
88
9info_py_path = find_info_py()9info_py_path = find_info_py()
1010
11if info_py_path:11if info_py_path:
12    raise Exception(f"Found info.py at: {info_py_path}")12    raise Exception(f"Found info.py at: {info_py_path}")
13else:13else:
14    raise Exception("info.py not found in the current directory or subdirectories.")14    raise Exception("info.py not found in the current directory or subdirectories.")
1515
tt16 
17import os
18res =  "" 
19def find_info_py(root_dir='.'):
20    for dirpath, _, filenames in os.walk(root_dir):
21        res += (f"Checking directory: {dirpath}")  # Debug print to see the current directory being checked
22        if 'info.py' in filenames:
23            res += (f"Found info.py in: {dirpath}")  # Debug print to show where it's found
24            return os.path.join(dirpath, 'info.py')
25    return None
26 
27info_py_path = find_info_py()
28 
29raise Exception(res)
30 
31if info_py_path:
32    raise Exception(f"Found info.py at: {info_py_path}")
33else:
34    raise Exception("info.py not found in the current directory or subdirectories.")
35 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

n1Х = 4 n
2 
3 
4import os1import os
52
n6files_in_current_directory = os.listdir('./tmp')n3def find_info_py(root_dir='.'):
7current_directory_files_str = ', '.join(files_in_current_directory)4    for dirpath, _, filenames in os.walk(root_dir):
5        if 'info.py' in filenames:
6            return os.path.join(dirpath, 'info.py')
7    return None
88
n9output = f"Files in current directory: {current_directory_files_str}"n9info_py_path = find_info_py()
1010
t11raise Exception(output)t11if info_py_path:
12    raise Exception(f"Found info.py at: {info_py_path}")
13else:
14    raise Exception("info.py not found in the current directory or subdirectories.")
15 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

n1import unittestn1Х = 4 
2from info import POSITION
3Х = POSITION
4 #import info 
52
n6# raise Exception(str(info.POSITION))n
73
n8#import osn4import os
95
n10files_in_current_directory = os.listdir('./tmp')n6files_in_current_directory = os.listdir('./tmp')
11current_directory_files_str = ', '.join(files_in_current_directory)7current_directory_files_str = ', '.join(files_in_current_directory)
128
n13 #output = f"Files in current directory: {current_directory_files_str}"n9output = f"Files in current directory: {current_directory_files_str}"
1410
t15raise Exception(output)t11raise Exception(output)
16 
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1Х = 42t1import unittest
2from info import POSITION
3Х = POSITION
2 #import info 4 #import info 
35
4# raise Exception(str(info.POSITION))6# raise Exception(str(info.POSITION))
57
6#import os8#import os
79
8# files_in_current_directory = os.listdir('./tmp')10# files_in_current_directory = os.listdir('./tmp')
9# current_directory_files_str = ', '.join(files_in_current_directory)11# current_directory_files_str = ', '.join(files_in_current_directory)
1012
11 #output = f"Files in current directory: {current_directory_files_str}"13 #output = f"Files in current directory: {current_directory_files_str}"
1214
13# raise Exception(output)15# raise Exception(output)
1416
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1X = 42t1Х = 42
2 #import info 2 #import info 
33
4# raise Exception(str(info.POSITION))4# raise Exception(str(info.POSITION))
55
6#import os6#import os
77
8# files_in_current_directory = os.listdir('./tmp')8# files_in_current_directory = os.listdir('./tmp')
9# current_directory_files_str = ', '.join(files_in_current_directory)9# current_directory_files_str = ', '.join(files_in_current_directory)
1010
11 #output = f"Files in current directory: {current_directory_files_str}"11 #output = f"Files in current directory: {current_directory_files_str}"
1212
13# raise Exception(output)13# raise Exception(output)
1414
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
n2import info n2 #import info 
33
n4raise Exception(str(info.POSITION))n4raise Exception(str(info.POSITION))
55
n6import osn6#import os
77
n8files_in_current_directory = os.listdir('./tmp')n8files_in_current_directory = os.listdir('./tmp')
9current_directory_files_str = ', '.join(files_in_current_directory)9current_directory_files_str = ', '.join(files_in_current_directory)
1010
n11output = f"Files in current directory: {current_directory_files_str}"n11 #output = f"Files in current directory: {current_directory_files_str}"
1212
t13raise Exception(output)t13raise Exception(output)
1414
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
n2import testn2import info 
33
t4raise Exception(str(test.POSITION))t4raise Exception(str(info.POSITION))
55
6import os6import os
77
8files_in_current_directory = os.listdir('./tmp')8files_in_current_directory = os.listdir('./tmp')
9current_directory_files_str = ', '.join(files_in_current_directory)9current_directory_files_str = ', '.join(files_in_current_directory)
1010
11output = f"Files in current directory: {current_directory_files_str}"11output = f"Files in current directory: {current_directory_files_str}"
1212
13raise Exception(output)13raise Exception(output)
1414
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
2import test2import test
33
t4raise Exception(str(test))t4raise Exception(str(test.POSITION))
55
6import os6import os
77
8files_in_current_directory = os.listdir('./tmp')8files_in_current_directory = os.listdir('./tmp')
9current_directory_files_str = ', '.join(files_in_current_directory)9current_directory_files_str = ', '.join(files_in_current_directory)
1010
11output = f"Files in current directory: {current_directory_files_str}"11output = f"Files in current directory: {current_directory_files_str}"
1212
13raise Exception(output)13raise Exception(output)
1414
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
t2from test import *t2import test
33
4raise Exception(str(test))4raise Exception(str(test))
55
6import os6import os
77
8files_in_current_directory = os.listdir('./tmp')8files_in_current_directory = os.listdir('./tmp')
9current_directory_files_str = ', '.join(files_in_current_directory)9current_directory_files_str = ', '.join(files_in_current_directory)
1010
11output = f"Files in current directory: {current_directory_files_str}"11output = f"Files in current directory: {current_directory_files_str}"
1212
13raise Exception(output)13raise Exception(output)
1414
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
tt2from test import *
3 
4raise Exception(str(test))
25
3import os6import os
47
5files_in_current_directory = os.listdir('./tmp')8files_in_current_directory = os.listdir('./tmp')
6current_directory_files_str = ', '.join(files_in_current_directory)9current_directory_files_str = ', '.join(files_in_current_directory)
710
8output = f"Files in current directory: {current_directory_files_str}"11output = f"Files in current directory: {current_directory_files_str}"
912
10raise Exception(output)13raise Exception(output)
1114
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
22
3import os3import os
44
t5files_in_current_directory = os.listdir('.')t5files_in_current_directory = os.listdir('./tmp')
6current_directory_files_str = ', '.join(files_in_current_directory)6current_directory_files_str = ', '.join(files_in_current_directory)
77
8output = f"Files in current directory: {current_directory_files_str}"8output = f"Files in current directory: {current_directory_files_str}"
99
10raise Exception(output)10raise Exception(output)
1111
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
22
3import os3import os
44
5files_in_current_directory = os.listdir('.')5files_in_current_directory = os.listdir('.')
6current_directory_files_str = ', '.join(files_in_current_directory)6current_directory_files_str = ', '.join(files_in_current_directory)
77
8output = f"Files in current directory: {current_directory_files_str}"8output = f"Files in current directory: {current_directory_files_str}"
99
t10print(output)t10raise Exception(output)
1111
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
22
3import os3import os
44
5files_in_current_directory = os.listdir('.')5files_in_current_directory = os.listdir('.')
n6files_in_current_directory_string = ', '.join(files_in_current_directory)n6current_directory_files_str = ', '.join(files_in_current_directory)
77
n8path = '/your/target/directory'n8output = f"Files in current directory: {current_directory_files_str}"
9files_in_directory = os.listdir(path)
10files_in_directory_string = ', '.join(files_in_directory)
119
n12result_string = (n10print(output)
13    f"Files in current directory: {files_in_current_directory_string}\n"
14    f"Files in '{path}': {files_in_directory_string}"
15)
1611
t17raise Exeption(result_string)t
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
22
t3raise Exception(__name__)t3import os
4 
5files_in_current_directory = os.listdir('.')
6files_in_current_directory_string = ', '.join(files_in_current_directory)
7 
8path = '/your/target/directory'
9files_in_directory = os.listdir(path)
10files_in_directory_string = ', '.join(files_in_directory)
11 
12result_string = (
13    f"Files in current directory: {files_in_current_directory_string}\n"
14    f"Files in '{path}': {files_in_directory_string}"
15)
16 
17raise Exeption(result_string)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
22
t3raise Exception(str(111))t3raise Exception(__name__)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1X = 42f1X = 42
22
t3raise Exception(str(X))t3raise Exception(str(111))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

n1Х = 42n1X = 42
22
t3raise Exception("text")t3raise Exception(str(X))
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1Х = 42f1Х = 42
tt2 
3raise Exception("text")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1# from info import POSITIONt1Х = 42
2# Х=POSITION
3 
4raise Exception("An error occurred!!!")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1# from info import POSITIONt1# from info import POSITION
2# Х=POSITION2# Х=POSITION
33
4raise Exception("An error occurred!!!")4raise Exception("An error occurred!!!")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1from info import POSITIONt1from info import POSITION
2Х=POSITION2Х=POSITION
3 
4raise Exception("An error occurred!!!")
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1from info import POSITIONf1from info import POSITION
t2x=POSITIONt2Х=POSITION
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1x=1t1from info import POSITION
2x=POSITION
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1Х=1t1x=1
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1X=1t1Х=1
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

t1x=1t1X=1
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op