Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kurs_alx_pcz
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
kurs_alx_pcz
Commits
83e17238
Commit
83e17238
authored
Nov 29, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
geometria - obsługa koła i trójkąta
parent
7935c5e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
6 deletions
+33
-6
geometria.py
dzien5/przyklady_funkcji/geometria.py
+22
-3
program_geometryczny.py
dzien5/przyklady_funkcji/program_geometryczny.py
+11
-3
No files found.
dzien5/przyklady_funkcji/geometria.py
View file @
83e17238
import
math
def
pole_kwadratu
(
a
):
return
a
*
a
def
obwod_kwadratu
(
a
):
return
4
*
a
def
pole_prostokata
(
a
,
b
):
return
a
*
b
def
obwod_prostokata
(
a
,
b
):
return
2
*
a
+
2
*
b
def
pole_kola
(
r
):
return
math
.
pi
*
r
*
r
def
obwod_kola
(
r
):
return
2
*
math
.
pi
*
r
def
poprawny_trojkat
(
a
,
b
,
c
):
'''
Funkcja sprawdza, czy podane boki tworzą trójkąt, i zwraca True albo False
'''
return
a
<
b
+
c
and
b
<
a
+
c
and
c
<
a
+
b
def
pole_trojkata
(
a
,
b
,
c
):
p
=
(
a
+
b
+
c
)
/
2
return
math
.
sqrt
(
p
*
(
p
-
a
)
*
(
p
-
b
)
*
(
p
-
c
))
def
obwod_trojkata
(
a
,
b
,
c
):
return
a
+
b
+
c
if
__name__
==
'__main__'
:
print
(
'Testowe wywołania funkcji:'
)
print
(
'pole kwadratu 5:'
,
pole_kwadratu
(
5
))
print
(
'pole kwadratu 7.5:'
,
pole_kwadratu
(
7.5
))
print
(
'pole prostokąta 3×4:'
,
pole_prostokata
(
3
,
4
))
...
...
dzien5/przyklady_funkcji/program_geometryczny.py
View file @
83e17238
...
...
@@ -4,11 +4,9 @@ tekst_menu = '''Wybierz rodzaj figury:
* K - kwadrat
* P - prostokąt
* O - koło
* T - trójkąt
* Q - wyjście z programu'''
# TODO dodaj obsługę koła do definicji funkcji
# TODO do programu oraz definicji funkcji dodaj obsługę trójkąta (w oparciu o 3 boki, jak w zadaniu domowym)
while
True
:
print
(
tekst_menu
)
wybor
=
input
(
'Twój wybór: '
)
.
upper
()
...
...
@@ -30,6 +28,16 @@ while True:
pole
=
pole_kola
(
r
)
obw
=
obwod_kola
(
r
)
print
(
f
'Koło o promieniu {r} ma pole {pole} oraz obwód {obw}'
)
elif
wybor
==
'T'
:
a
=
float
(
input
(
'Podaj bok a: '
))
b
=
float
(
input
(
'Podaj bok b: '
))
c
=
float
(
input
(
'Podaj bok c: '
))
if
poprawny_trojkat
(
a
,
b
,
c
):
pole
=
pole_trojkata
(
a
,
b
,
c
)
obw
=
obwod_trojkata
(
a
,
b
,
c
)
print
(
f
'Tójkąt o bokach {a} {b} {c} ma pole {pole} oraz obwód {obw}'
)
else
:
print
(
f
'Niew da się zbudować trójkąta z boków {a} {b} {c}'
)
else
:
print
(
'Niepoprawny wybór'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment