-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinux_command_improver.py
More file actions
36 lines (32 loc) · 1.07 KB
/
Copy pathLinux_command_improver.py
File metadata and controls
36 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import random # generování náhodných čísel
import os # práce s cestami k souborům
def vyber_soubor(obtiznost):
absolutni_cesta = r"C:\Users\olgah\Desktop\DataFiles"
os.chdir(absolutni_cesta)
if obtiznost == 1:
file_name = "1.txt"
elif obtiznost == 2:
file_name = "2.txt"
elif obtiznost == 3:
file_name = "3.txt"
else:
print("Neplatná obtížnost.")
return None
file_path = os.path.join(absolutni_cesta, file_name)
return file_path
def zobraz_prikaz(soubor):
try:
with open(soubor, 'r', encoding='utf-8') as file:
prikazy = file.readlines()
nahodny_prikaz = random.choice(prikazy)
print("Náhodný příkaz:")
print(nahodny_prikaz)
except FileNotFoundError:
print("Soubor nebyl nalezen.")
while True:
obtiznost = int(input("Zvolte obtížnost (1, 2 nebo 3) nebo 0 pro ukončení: "))
if obtiznost == 0:
break
soubor = vyber_soubor(obtiznost)
if soubor:
zobraz_prikaz(soubor)