-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
108 lines (87 loc) · 2.85 KB
/
main.py
File metadata and controls
108 lines (87 loc) · 2.85 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
unit = "cm"
def square_area(a):
return a * a
def rectangle_area(a, b):
return a * b
def circle_area(r):
return 3.14 * r * r
def triangle_area(a, h):
return (a * h) / 2
def cube_volume(a):
return a * a * a
def cuboid_volume(length, width, height):
return length * width * height
def choose_unit():
global unit
print("1. mm")
print("2. cm")
print("3. dm")
print("4. m")
print("5. km")
choice = int(input("Zadejte jednotku ve které chcete počítat > "))
if choice == 1:
unit = "mm"
elif choice == 2:
unit = "cm"
elif choice == 3:
unit = "dm"
elif choice == 4:
unit = "m"
elif choice == 5:
unit = "km"
else:
print("Neplatná volba, nastavena výchozí jednotka cm")
unit = "cm"
def select_and_use_function():
print("Vyberte tvar:")
print("1. Čtverec")
print("2. Obdelník")
print("3. Kruh")
print("4. Trojúhelník")
print("5. Krychle (objem)")
print("6. Kvádr (objem)")
choice = int(input("Zadejte číslo tvaru > "))
if choice == 1:
side = float(input("Zadejte délku strany čtverce > "))
result = square_area(side)
print("Obsah čtverce je " + str(result) + " " + unit + "²")
elif choice == 2:
width = float(input("Zadejte šířku obdelníku > "))
height = float(input("Zadejte výšku obdelníku > "))
result = rectangle_area(width, height)
print("Obsah obdelníku je " + str(result) + " " + unit + "²")
elif choice == 3:
radius = float(input("Zadejte poloměr kruhu > "))
result = circle_area(radius)
print("Obsah kruhu je " + str(result) + " " + unit + "²")
elif choice == 4:
base = float(input("Zadejte délku základny trojúhelníku > "))
height = float(input("Zadejte výšku trojúhelníku > "))
result = triangle_area(base, height)
print("Obsah trojúhelníku je " + str(result) + " " + unit + "²")
elif choice == 5:
side = float(input("Zadejte délku hrany krychle > "))
result = cube_volume(side)
print("Objem krychle je " + str(result) + " " + unit + "³")
elif choice == 6:
length = float(input("Zadejte délku hrany kvádra > "))
width = float(input("Zadejte šířku kvádra > "))
height = float(input("Zadejte výšku kvádra > "))
result = cuboid_volume(length, width, height)
print("Objem kvádru je " + str(result) + " " + unit + "³")
else:
print("Neplatná volba")
menu()
def menu():
print("1. Vybrat jednotku a spočítat")
print("2. Konec")
choice = int(input("Zadejte volbu > "))
if choice == 1:
choose_unit()
select_and_use_function()
elif choice == 2:
print("Konec programu")
else:
print("Neplatná volba")
menu()
menu()