From e74fdbfdbd84c8946d118ae644e9e4b92d5e5a8f Mon Sep 17 00:00:00 2001 From: MuhammadZiad <122127254+MuhammadZiad@users.noreply.github.com> Date: Tue, 31 Jan 2023 22:51:08 +0100 Subject: [PATCH 1/4] Create bonus.py using lambda to filter odd numbers --- bonus.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 bonus.py diff --git a/bonus.py b/bonus.py new file mode 100644 index 0000000..80bb8f0 --- /dev/null +++ b/bonus.py @@ -0,0 +1,8 @@ +# Bonus 2 +my_list = [1, 5, 4, 6, 8, 11, 3, 12] +even_list = list(filter(lambda x: (x%2 == 0) , my_list)) # using lambda to filter even numbers +print("the even numbers in the list are: ") +print(even_list) +odd_list = list(filter(lambda x: (x%2 != 0) , my_list)) # using lambda to filter odd numbers +print("the odd numbers in the list are: ") +print(odd_list) \ No newline at end of file From 37bbb4185e082d6225ed103bc8c80be33ca3a0b5 Mon Sep 17 00:00:00 2001 From: MuhammadZiad <122127254+MuhammadZiad@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:01:16 +0100 Subject: [PATCH 2/4] 2 --- Assignment2.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Assignment2.py diff --git a/Assignment2.py b/Assignment2.py new file mode 100644 index 0000000..f6497bc --- /dev/null +++ b/Assignment2.py @@ -0,0 +1,10 @@ + +# Assignment 2 +''' this program accepts a hyphen-separated sequence of words as input and prints them + after sorting them alphabetically ''' + +words = input(("Enter the words separated by a hyphen as a list: "))# asking to give the words in the sequence +words_list = words.split('-') # put the words in a list +words_list.sort() # Sorting the words +result = '-'.join(words_list) # Joining the words with a hyphen +print("the words after sorting them alphabetically: " + result) # Printing the output From a1cffde72663145b0d405431e183d885902d480c Mon Sep 17 00:00:00 2001 From: MuhammadZiad <122127254+MuhammadZiad@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:01:24 +0100 Subject: [PATCH 3/4] 3 --- Assignment3.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Assignment3.py diff --git a/Assignment3.py b/Assignment3.py new file mode 100644 index 0000000..7fa115a --- /dev/null +++ b/Assignment3.py @@ -0,0 +1,15 @@ +# # Assignment 3 +''' this function is used to check whether a number is perfect or not ''' +def perf_num(n): + sum = 0 + for i in range(1, n): # the number n is not included + if(n % i == 0): + sum += i + return sum == n + +# asking to give a number to check +n = int(input("Please enter a number: ")) +if perf_num(n): + print(f" {n} is a perfect number!") +else: + print(f" {n} is not a perfect number!") \ No newline at end of file From e5daa161152347081f137ed3ab9feb948680ece4 Mon Sep 17 00:00:00 2001 From: MuhammadZiad <122127254+MuhammadZiad@users.noreply.github.com> Date: Tue, 31 Jan 2023 23:01:31 +0100 Subject: [PATCH 4/4] 4 --- Assignment4.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Assignment4.py diff --git a/Assignment4.py b/Assignment4.py new file mode 100644 index 0000000..ded16b0 --- /dev/null +++ b/Assignment4.py @@ -0,0 +1,12 @@ +# # Assignment 4 +''' this program composes a random password ''' +import random +import string + +def random_password(length): + items = string.ascii_letters + string.digits + string.punctuation # upper & lowercase letters , numbers and special symbols + password = ''.join(random.choice(items) for i in range(length)) # generating the password from the random choices + print("here is your random password :", password) +# # examples +random_password(8) +random_password(10)