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
16 changes: 16 additions & 0 deletions Assignment_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Answer 1
# Write a Python function that prints out the first n rows of Pascal's triangle. Note : Pascal's triangle is an arithmetic and geometric figure first imagined by Blaise Pascal.

# Sample Pascal's triangle :


from math import factorial
def number_of_rows(n):
for i in range(n):
for j in range(n - i + 1):
print(end=" ")
for j in range(i + 1):
print(factorial(i)//(factorial(j)*factorial(i-j)), end=" ")
print("")
n = 5
number_of_rows(n)
13 changes: 13 additions & 0 deletions Assignment_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Answer 2
# Write a Python program that accepts a hyphen-separated sequence of words as input and prints the words in a hyphen-separated sequence after sorting them alphabetically.

# Sample Items : green-red-yellow-black-white Expected Result : black-green-red-white-yellow#

items = []
def res(n):
for i in n:
items.append(i)
items.sort()
return "-".join(items)
user_input = input("Enter:").split("-")
print(res(user_input))
19 changes: 19 additions & 0 deletions Assignment_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Assement 3
# Write a Python function to check whether a number is perfect or not.

# According to Wikipedia : In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself (also known as its aliquot sum). Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself).

# Example : The first perfect number is 6, because 1, 2, and 3 are its proper positive divisors, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6. The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.

def perfect_number(n):
sum = 0
for i in range(1, n):
if n % i == 0:
sum += i
if (sum == n):
return "The number is a Perfect number!"
else:
return "The number is not a Perfect number!"
num = int(input("Enter any number: "))
print(perfect_number(num))

38 changes: 38 additions & 0 deletions Assignment_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Answer 4
"""Create a user interface that generates a random password with the given
user input such as length, number of lowercase letters and uppercase letters and
adding special characters(!,?, .,etc.)"""

from tkinter import *
import random
import string


screen = Tk()

screen.title("Password Generator!")
screen.geometry('350x200')
screen.title("Password Generator!")

length_text = Label(screen, text="Enter the number of characters")
length_text.pack()

length = Entry(screen, width=20)
length.pack(padx=20, pady=20)

lower = string.ascii_lowercase
upper = string.ascii_uppercase
num =string.digits
speialchar = string.punctuation
all = lower + upper + num + speialchar
def generate():
l = int(length.get())
temp = random.sample(all,l)
password= Label(screen)
password.configure(text ="Password: "+ "".join(temp))
password.pack()
generate_btn = Button(screen, text="Generate Password", command=generate)
generate_btn.pack()

screen.mainloop()

16 changes: 16 additions & 0 deletions Bonus_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Bonus 1
Write a Python program to sort a list of dictionaries using Lambda. Original list of dictionaries :
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]

Sorting the List of dictionaries :
[{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}, {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}]"""



models_list = [{'make': 'Nokia', 'model': 216, 'color': 'Black'}, {'make': 'Mi Max', 'model': '2', 'color': 'Gold'}, {'make': 'Samsung', 'model': 7, 'color': 'Blue'}]
print("Original list of dictionaries:")
print(models_list)
sorted_models = sorted(models_list, key=lambda k: k['color'])

print("\nSorted list of dictionaries:")
print(sorted_models)
20 changes: 20 additions & 0 deletions Bonus_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Bonus 2 Answer
# Write a Python program to filter a list of integers using Lambda.

# Original list of integers: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Even numbers from the said list: [2, 4, 6, 8, 10]

# Odd numbers from the said list: [1, 3, 5, 7, 9]

number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print("Original list of integers:")
print(number)

print("Even numbers from the said list:")
even_nums = list(filter(lambda x: x%2 == 0, number))
print(even_nums)

print("Odd numbers from the said list:")
odd_nums = list(filter(lambda x: x%2 != 0, number))
print(odd_nums)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Sample Pascal's triangle :
Pascal's triangle
Each number is the two numbers above it added together


## Assignment 2

Write a Python program that accepts a hyphen-separated sequence of words as input and prints the words in a hyphen-separated sequence after sorting them alphabetically.
Expand Down
Binary file added imag_output/Ass 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imag_output/Ass 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imag_output/Ass 3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imag_output/Ass 4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imag_output/bonus 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imag_output/bonus 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.