From f763a3426e1b99a0c231d40034fbe60fdc330116 Mon Sep 17 00:00:00 2001 From: Tariq Smith Date: Sat, 8 Apr 2023 15:16:06 +0100 Subject: [PATCH 1/4] Completed Basic Version --- .idea/.gitignore | 3 +++ .idea/Random-Name-Generator.iml | 8 ++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++++ .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ main.py | 20 +++++++++++++++++++ 7 files changed, 55 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Random-Name-Generator.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/Random-Name-Generator.iml b/.idea/Random-Name-Generator.iml new file mode 100644 index 0000000..d27d2cf --- /dev/null +++ b/.idea/Random-Name-Generator.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..a4652f3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..867f71b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.py b/main.py index e69de29..f71d45a 100644 --- a/main.py +++ b/main.py @@ -0,0 +1,20 @@ +import random + +short_list = input("Please type the names into the list: \n").split(" ") + +is_number = False +number_of_people = "" + +while not is_number: + number_of_people = input("How many people would you like to select? \n") + if number_of_people.isnumeric(): + number_of_people = int(number_of_people) + is_number = True + else: + continue + +new_list = random.sample(short_list, number_of_people) +print("Here is your random sample list: \n" + str(new_list)) + + + From 894a6e9dc20933e9516f36aa7fd835fbc67219f7 Mon Sep 17 00:00:00 2001 From: Tariq Smith Date: Sat, 8 Apr 2023 15:51:59 +0100 Subject: [PATCH 2/4] Completed with Functions --- main.py | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index f71d45a..e1af476 100644 --- a/main.py +++ b/main.py @@ -1,20 +1,37 @@ import random -short_list = input("Please type the names into the list: \n").split(" ") -is_number = False -number_of_people = "" +def main(): + print(random_sample(input_list(), number_people())) -while not is_number: - number_of_people = input("How many people would you like to select? \n") - if number_of_people.isnumeric(): - number_of_people = int(number_of_people) - is_number = True - else: - continue -new_list = random.sample(short_list, number_of_people) -print("Here is your random sample list: \n" + str(new_list)) +def input_list(): + short_list = input("Please type the names into the list: \n").split(" ") + return short_list + + +def number_people(): + num_people = 0 + while num_people == 0: + people = input("How many people would you like to select? \n") + num_people = is_positive_integer(people) + return num_people + + +def is_positive_integer(number): + if number.isnumeric(): + if int(number) != 0: + number = int(number) + return number + return 0 + + +def random_sample(original_list, num_people): + new_list = random.sample(original_list, num_people) + return "Here is your random sample list: \n" + str(new_list) + + +main() From 2d6ab805f63b9d565842b982acfe00adfeec0249 Mon Sep 17 00:00:00 2001 From: Tariq Smith Date: Sat, 8 Apr 2023 16:05:29 +0100 Subject: [PATCH 3/4] Completed with a fewerror messages and comments --- main.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index e1af476..2fecdf4 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,17 @@ +# imported the 'randomize' package import random - +# This is the main function where all functions will be carried out through def main(): print(random_sample(input_list(), number_people())) - +# This input function carries out the functionality to input your names into a list from the user def input_list(): short_list = input("Please type the names into the list: \n").split(" ") return short_list - +# This function is to allow the user to type and pick the amount of names they want from the starting list, +# into the new randomized list, and contains an error function within def number_people(): num_people = 0 while num_people == 0: @@ -17,20 +19,25 @@ def number_people(): num_people = is_positive_integer(people) return num_people - +# This function is used to varify if the user has typed in a positive integer def is_positive_integer(number): if number.isnumeric(): if int(number) != 0: number = int(number) return number - return 0 - - + else: + print("You can't type 0\n") + return 0 + else: + print("Please type in a positive whole number\n") + return 0 + +# This function is used to create and randomize the new list using the users values inputted def random_sample(original_list, num_people): new_list = random.sample(original_list, num_people) return "Here is your random sample list: \n" + str(new_list) - +# This calls the main function main() From d4a2fa57dce58be0aef280a592a2b51801af0b32 Mon Sep 17 00:00:00 2001 From: Tariq Smith Date: Sat, 8 Apr 2023 16:51:50 +0100 Subject: [PATCH 4/4] Completed Project with an extra error check for inputing names --- main.py | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 2fecdf4..03d6d8c 100644 --- a/main.py +++ b/main.py @@ -2,16 +2,40 @@ import random # This is the main function where all functions will be carried out through + + def main(): print(random_sample(input_list(), number_people())) -# This input function carries out the functionality to input your names into a list from the user +# This input_list function carries out the functionality to input your names into a list from the user, +# and contains an error check function + + def input_list(): short_list = input("Please type the names into the list: \n").split(" ") - return short_list + return non_letters(short_list) + +# The non_letters function filers out any typos with the list from the user, +# this includes any character on the keyboard that is not in the alphabet + + +def non_letters(short_list): + update_list = [] + for name in short_list: + update_name = "" + for letter in name: + if letter.isalpha(): + update_name += letter + else: + continue + update_list.append(update_name) + return update_list + + +# The number_people function is to allow the user to type and pick the amount of names they want from the starting list, +# into the new randomized list, and contains an error check function within + -# This function is to allow the user to type and pick the amount of names they want from the starting list, -# into the new randomized list, and contains an error function within def number_people(): num_people = 0 while num_people == 0: @@ -19,7 +43,9 @@ def number_people(): num_people = is_positive_integer(people) return num_people -# This function is used to varify if the user has typed in a positive integer +# The is_positive_integer function is used to varify if the user has typed in a positive integer + + def is_positive_integer(number): if number.isnumeric(): if int(number) != 0: @@ -32,13 +58,17 @@ def is_positive_integer(number): print("Please type in a positive whole number\n") return 0 -# This function is used to create and randomize the new list using the users values inputted +# The random_sample function is used to create and randomize the new list using the users values inputted + + def random_sample(original_list, num_people): new_list = random.sample(original_list, num_people) return "Here is your random sample list: \n" + str(new_list) # This calls the main function + main() +