Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Assignment2.py
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions Assignment3.py
Original file line number Diff line number Diff line change
@@ -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!")
12 changes: 12 additions & 0 deletions Assignment4.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions bonus.py
Original file line number Diff line number Diff line change
@@ -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)