From 5b68695e4d358d07ab759afd1ed670fd296cec5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fevzi=20Ba=C4=9Fr=C4=B1a=C3=A7=C4=B1k?= <124450541+fevzibagriacik@users.noreply.github.com> Date: Sat, 8 Mar 2025 13:45:46 +0300 Subject: [PATCH 1/5] =?UTF-8?q?Create=20weighted=5FFevzi=5FBa=C4=9Fr=C4=B1?= =?UTF-8?q?a=C3=A7=C4=B1k.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 "Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" diff --git "a/Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" "b/Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" new file mode 100644 index 0000000..0b7f026 --- /dev/null +++ "b/Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" @@ -0,0 +1,8 @@ +import random + +def weighted_srs(population, n): + return random.sample(population, n) + +population = ["Ali", "Ayşe", "Fatma", "Kazım", "Mehmet", "Ahmet"] + +print(weighted_srs(population, 3)) From d3660afe6098ade17b48028e134195848c80a332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fevzi=20Ba=C4=9Fr=C4=B1a=C3=A7=C4=B1k?= <124450541+fevzibagriacik@users.noreply.github.com> Date: Mon, 10 Mar 2025 11:31:17 +0300 Subject: [PATCH 2/5] =?UTF-8?q?Update=20and=20rename=20weighted=5FFevzi=5F?= =?UTF-8?q?Ba=C4=9Fr=C4=B1a=C3=A7=C4=B1k.py=20to=20weighted=5Ffevzi=5Fbagr?= =?UTF-8?q?iacik.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ghted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" | 8 -------- Week03/weighted_fevzi_bagriacik.py | 9 +++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) delete mode 100644 "Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" create mode 100644 Week03/weighted_fevzi_bagriacik.py diff --git "a/Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" "b/Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" deleted file mode 100644 index 0b7f026..0000000 --- "a/Week03/weighted_Fevzi_Ba\304\237r\304\261a\303\247\304\261k.py" +++ /dev/null @@ -1,8 +0,0 @@ -import random - -def weighted_srs(population, n): - return random.sample(population, n) - -population = ["Ali", "Ayşe", "Fatma", "Kazım", "Mehmet", "Ahmet"] - -print(weighted_srs(population, 3)) diff --git a/Week03/weighted_fevzi_bagriacik.py b/Week03/weighted_fevzi_bagriacik.py new file mode 100644 index 0000000..dae4bf0 --- /dev/null +++ b/Week03/weighted_fevzi_bagriacik.py @@ -0,0 +1,9 @@ +import random + +def weighted_srs(): + population = ["Ali", "Ayşe", "Fatma", "Kazım", "Mehmet"] + weight = [20, 20, 20, 20, 20] + k = 3 + return random.choices(population, weight, k=k) + +print(weighted_srs()) From c16a353f6098e46417c963ce9fea56cf0acb8c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fevzi=20Ba=C4=9Fr=C4=B1a=C3=A7=C4=B1k?= <124450541+fevzibagriacik@users.noreply.github.com> Date: Tue, 11 Mar 2025 22:40:13 +0300 Subject: [PATCH 3/5] Update weighted_fevzi_bagriacik.py --- Week03/weighted_fevzi_bagriacik.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Week03/weighted_fevzi_bagriacik.py b/Week03/weighted_fevzi_bagriacik.py index dae4bf0..45dec1a 100644 --- a/Week03/weighted_fevzi_bagriacik.py +++ b/Week03/weighted_fevzi_bagriacik.py @@ -1,9 +1,9 @@ import random -def weighted_srs(): - population = ["Ali", "Ayşe", "Fatma", "Kazım", "Mehmet"] - weight = [20, 20, 20, 20, 20] - k = 3 +def weighted_srs(population, weight, k): + ##population = ["Ali", "Ayşe", "Fatma", "Kazım", "Mehmet"] + ##weight = [20, 20, 20, 20, 20] + ##k = 3 return random.choices(population, weight, k=k) -print(weighted_srs()) +print(weighted_srs(["Ali", "Ayse", "Fatma", "Kazım", "Mehmet"], [20, 20, 20, 20, 20], 3)) From 3bfacedbb662b92b411438e58b793867e439decd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fevzi=20Ba=C4=9Fr=C4=B1a=C3=A7=C4=B1k?= <124450541+fevzibagriacik@users.noreply.github.com> Date: Thu, 20 Mar 2025 15:59:36 +0300 Subject: [PATCH 4/5] Update weighted_fevzi_bagriacik.py --- Week03/weighted_fevzi_bagriacik.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Week03/weighted_fevzi_bagriacik.py b/Week03/weighted_fevzi_bagriacik.py index 45dec1a..4bb85e6 100644 --- a/Week03/weighted_fevzi_bagriacik.py +++ b/Week03/weighted_fevzi_bagriacik.py @@ -1,9 +1,4 @@ import random def weighted_srs(population, weight, k): - ##population = ["Ali", "Ayşe", "Fatma", "Kazım", "Mehmet"] - ##weight = [20, 20, 20, 20, 20] - ##k = 3 return random.choices(population, weight, k=k) - -print(weighted_srs(["Ali", "Ayse", "Fatma", "Kazım", "Mehmet"], [20, 20, 20, 20, 20], 3)) From 19c0f831f509c69fc34187fcd7cf2bb90dd101e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fevzi=20Ba=C4=9Fr=C4=B1a=C3=A7=C4=B1k?= <124450541+fevzibagriacik@users.noreply.github.com> Date: Sat, 26 Apr 2025 12:54:59 +0300 Subject: [PATCH 5/5] Update weighted_fevzi_bagriacik.py --- Week03/weighted_fevzi_bagriacik.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Week03/weighted_fevzi_bagriacik.py b/Week03/weighted_fevzi_bagriacik.py index 4bb85e6..3fe8700 100644 --- a/Week03/weighted_fevzi_bagriacik.py +++ b/Week03/weighted_fevzi_bagriacik.py @@ -1,4 +1,6 @@ import random -def weighted_srs(population, weight, k): - return random.choices(population, weight, k=k) +def weighted_srs(population, n, weight, with_replacement=False): + if with_replacement == True or weight != None: + return random.choices(population, weight=weight, k=n) + return random.sample(population, n)