-
↥ back to top
+b. Option 2
+
+ numpy.empty(shape=(0,0))
+
+array([], shape=(0, 0), dtype=float64)
+
+
diff --git a/find_matches/find_matches.py b/find_matches/find_matches.py
index fad9602..ed074a6 100644
--- a/find_matches/find_matches.py
+++ b/find_matches/find_matches.py
@@ -1,7 +1,6 @@
-import sys
-import csv
-import re
-
+import sys #for comand line argv
+import csv #for work with csv
+import re #for checks matches
class FindMatches(object):
""" Takes a .csv input file and a matching type and returns a copy of the original csv with the unique identifier of the person each row represents prepended to the row.
diff --git a/guicalc.py b/guicalc.py
new file mode 100644
index 0000000..ad0b019
--- /dev/null
+++ b/guicalc.py
@@ -0,0 +1,90 @@
+# Import the tkinter library for creating GUI applications
+import tkinter as tk
+
+# Create the main application window
+root = tk.Tk()
+root.title("Calculator") # Set the window title
+root.geometry("300x400") # Set window size (width x height)
+
+# Create an Entry widget to display numbers and results
+entry = tk.Entry(
+ root,
+ font=("Arial", 20), # Font style and size
+ borderwidth=5, # Thickness of border
+ relief="ridge", # Border style
+ justify="right" # Align text to the right
+)
+entry.pack(fill="both", padx=10, pady=10)
+
+# Function to insert numbers/operators when a button is clicked
+def click(value):
+ entry.insert(tk.END, value) # Insert value at the end of the entry box
+
+# Function to clear the display
+def clear():
+ entry.delete(0, tk.END) # Delete everything from entry box
+
+# Function to evaluate the expression
+def calculate():
+ try:
+ # Evaluate the mathematical expression entered by the user
+ result = eval(entry.get())
+ entry.delete(0, tk.END) # Clear entry box
+ entry.insert(tk.END, result) # Display result
+ except:
+ # If any error occurs (invalid expression)
+ entry.delete(0, tk.END)
+ entry.insert(tk.END, "Error")
+
+# List of calculator buttons in order
+buttons = [
+ '7', '8', '9', '/',
+ '4', '5', '6', '*',
+ '1', '2', '3', '-',
+ '0', '.', '=', '+'
+]
+
+# Create a frame to hold all the buttons
+frame = tk.Frame(root)
+frame.pack()
+
+row = 0
+col = 0
+
+# Create buttons dynamically using a loop
+for btn in buttons:
+ if btn == "=":
+ # '=' button performs calculation
+ tk.Button(
+ frame,
+ text=btn,
+ width=5,
+ height=2,
+ command=calculate
+ ).grid(row=row, column=col)
+ else:
+ # Other buttons insert numbers/operators
+ tk.Button(
+ frame,
+ text=btn,
+ width=5,
+ height=2,
+ command=lambda b=btn: click(b)
+ ).grid(row=row, column=col)
+
+ col += 1
+ if col > 3: # Move to next row after 4 buttons
+ col = 0
+ row += 1
+
+# Clear button placed below the calculator buttons
+tk.Button(
+ root,
+ text="Clear",
+ width=20,
+ height=2,
+ command=clear
+).pack(pady=10)
+
+# Start the GUI event loop
+root.mainloop()
diff --git a/programs/add_to_zero.py b/programs/add_to_zero.py
index 3b2dace..a48e555 100644
--- a/programs/add_to_zero.py
+++ b/programs/add_to_zero.py
@@ -35,4 +35,4 @@ def add_to_zero(nums):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/anagram_of_palindrome.py b/programs/anagram_of_palindrome.py
index d35d09b..2a64545 100644
--- a/programs/anagram_of_palindrome.py
+++ b/programs/anagram_of_palindrome.py
@@ -44,4 +44,4 @@ def is_anagram_of_palindrome(word):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/binary_search.py b/programs/binary_search.py
index f232ca4..843d77d 100644
--- a/programs/binary_search.py
+++ b/programs/binary_search.py
@@ -46,4 +46,4 @@ def binary_search(val):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED"
+ print("ALL TESTS PASSED")
diff --git a/programs/bst_add_child.py b/programs/bst_add_child.py
index e337202..566cec3 100644
--- a/programs/bst_add_child.py
+++ b/programs/bst_add_child.py
@@ -57,4 +57,4 @@ def insert(self, new_data):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/calculator.py b/programs/calculator.py
index 62e701b..ca9e038 100644
--- a/programs/calculator.py
+++ b/programs/calculator.py
@@ -68,7 +68,7 @@ def calculate(inner_expression, operators):
nxt = new_expr[op_index+1]
total = int(prev) * int(nxt)
new_expr = new_expr[:op_index-1] + str(total) + new_expr[op_index+2:]
- print new_expr
+ print(new_expr)
while operators['/'] != []:
op_index = operators['/'].pop()
diff --git a/programs/coins.py b/programs/coins.py
index da57787..9048b0c 100644
--- a/programs/coins.py
+++ b/programs/coins.py
@@ -89,4 +89,4 @@ def _coins_2(coins_left, combos, total):
results = doctest.testmod()
if not results.failed:
- print 'ALL TESTS PASSED!'
+ print("ALL TESTS PASSED!")
diff --git a/programs/count_employees.py b/programs/count_employees.py
index 08ace1b..63bbd5a 100644
--- a/programs/count_employees.py
+++ b/programs/count_employees.py
@@ -55,4 +55,4 @@ def count_employees(self):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED"
+ print("ALL TESTS PASSED!")
diff --git a/programs/count_recursively.py b/programs/count_recursively.py
index 799a455..f6e394d 100644
--- a/programs/count_recursively.py
+++ b/programs/count_recursively.py
@@ -19,4 +19,4 @@ def count_recursively(lst):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/create_queue.py b/programs/create_queue.py
index 70e2234..2445e09 100644
--- a/programs/create_queue.py
+++ b/programs/create_queue.py
@@ -67,5 +67,5 @@ def peek(self):
results = doctest.testmod()
if not results.failed:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/create_queue_ll.py b/programs/create_queue_ll.py
index b1d9267..d1747d1 100644
--- a/programs/create_queue_ll.py
+++ b/programs/create_queue_ll.py
@@ -171,5 +171,5 @@ def print_queue(self):
results = doctest.testmod()
if not results.failed:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/create_stack.py b/programs/create_stack.py
index a6bd1a9..ac9c42e 100644
--- a/programs/create_stack.py
+++ b/programs/create_stack.py
@@ -185,6 +185,6 @@ def find_min(self):
print
result = doctest.testmod()
if not result.failed:
- print "ALL TESTS PASSED. GOOD WORK!"
+ print("ALL TESTS PASSED. GOOD WORK!")
print
diff --git a/programs/decode_string.py b/programs/decode_string.py
index c0f4372..f890e2c 100644
--- a/programs/decode_string.py
+++ b/programs/decode_string.py
@@ -69,4 +69,4 @@ def _decode_2(s, decoded, i):
results = doctest.testmod()
if results.failed == 0:
- print 'ALL TESTS PASSED!'
+ print("ALL TESTS PASSED!")
diff --git a/programs/find_mode.py b/programs/find_mode.py
index ca361d4..15bb965 100644
--- a/programs/find_mode.py
+++ b/programs/find_mode.py
@@ -47,4 +47,4 @@ def find_mode(arr):
results = doctest.testmod()
if not results.failed:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/first_duplicate.py b/programs/first_duplicate.py
index 65d4b23..64c91f3 100644
--- a/programs/first_duplicate.py
+++ b/programs/first_duplicate.py
@@ -112,4 +112,4 @@ def first_duplicate_optimized(arr):
results = doctest.testmod()
if not results.failed:
- print "All tests passed!"
+ print("All tests passed!")
diff --git a/programs/highest_product_of_three.py b/programs/highest_product_of_three.py
index cc014ba..11dba55 100644
--- a/programs/highest_product_of_three.py
+++ b/programs/highest_product_of_three.py
@@ -63,4 +63,4 @@ def highest_product_of_three(list_of_ints):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED!"
+ print("ALL TESTS PASSED!")
diff --git a/programs/is_unique.py b/programs/is_unique.py
index 3431a9e..5b641d2 100644
--- a/programs/is_unique.py
+++ b/programs/is_unique.py
@@ -1,3 +1,28 @@
+# import unittest
+
+
+# def is_unique(string):
+# """ Takes a string and returns True if it has all unique characters. """
+
+# str_set = set(string)
+
+# return str_set == string
+
+
+# class Testing(unittest.TestCase):
+# def is_unique_test(self):
+# assertEqual(is_unique('asdfghjkl'), True)
+# assertEqual(is_unique('1234567asdf'), True)
+# assertEqual(is_unique('!@#$%^&asdfg123'), True)
+# assertEqual(is_unique('abcdABCD'), True)
+
+# assertEqual(is_unique('asdfghjkll'), False)
+# assertEqual(is_unique('1qwerty1'), False)
+# assertEqual(is_unique('poiu$asdf$'), False)
+
+# if __name__ == '__main__':
+# unittest.main()
+
import unittest
@@ -10,15 +35,15 @@ def is_unique(string):
class Testing(unittest.TestCase):
- def is_unique_test(self):
- assertEqual(is_unique('asdfghjkl'), True)
- assertEqual(is_unique('1234567asdf'), True)
- assertEqual(is_unique('!@#$%^&asdfg123'), True)
- assertEqual(is_unique('abcdABCD'), True)
-
- assertEqual(is_unique('asdfghjkll'), False)
- assertEqual(is_unique('1qwerty1'), False)
- assertEqual(is_unique('poiu$asdf$'), False)
+ def test_is_unique(self):
+ self.assertEqual(is_unique('asdfghjkl'), True)
+ self.assertEqual(is_unique('1234567asdf'), True)
+ self.assertEqual(is_unique('!@#$%^&asdfg123'), True)
+ self.assertEqual(is_unique('abcdABCD'), True)
+
+ self.assertEqual(is_unique('asdfghjkll'), False)
+ self.assertEqual(is_unique('1qwerty1'), False)
+ self.assertEqual(is_unique('poiu$asdf$'), False)
if __name__ == '__main__':
unittest.main()
diff --git a/programs/mysti_guess.py b/programs/mysti_guess.py
new file mode 100644
index 0000000..7ecdbbc
--- /dev/null
+++ b/programs/mysti_guess.py
@@ -0,0 +1,51 @@
+# Generate a random num
+import random
+
+# Specifying the range bt taking input
+print('Please enter the range of numbers -')
+min = int(input('Minimum : '))
+max = int(input('Maximum : '))
+num = random.randint(min,max)
+
+# attempts
+attempts = 5
+guessed = 0
+
+# loop
+while True :
+# take input guess
+ try:
+ print(f'You have only {attempts} attempts!')
+ guess = int(input(f'Guess the number between {min} and {max} : '))
+
+ # if num < guess : too low
+ if guess < num :
+ print('Too low!')
+ guessed += 1
+ attempts -= 1
+ if attempts == 0:
+ print('Attempts Over!')
+ print('Sorry! Try Next Time!')
+ print(f'The number was {num}')
+ break
+
+ # if num > guess : too high
+ elif guess > num :
+ print('Too high!')
+ guessed += 1
+ attempts -= 1
+ if attempts == 0:
+ print('Attempts Over!')
+ print('Sorry! Try Next Time!')
+ print(f'The number was {num}.')
+ break
+
+ # else num == guess : well done
+ else :
+ guessed += 1
+ print(f'Congratulations! You guessed the number in {guessed} attempts!')
+ break
+
+ # if invalid num : error
+ except ValueError:
+ print('Please enter a valid number')
diff --git a/programs/print_recursively.py b/programs/print_recursively.py
index 16e5c45..9920fda 100644
--- a/programs/print_recursively.py
+++ b/programs/print_recursively.py
@@ -10,7 +10,7 @@ def print_recursively(lst):
if not lst:
return
- print lst[0]
+ print (lst [0])
print_recursively(lst[1:])
@@ -20,4 +20,4 @@ def print_recursively(lst):
results = doctest.testmod()
if results.failed == 0:
- print "ALL TESTS PASSED"
+ print ("ALL TESTS PASSED")
\ No newline at end of file
diff --git a/programs/rommon_to_integer.py b/programs/rommon_to_integer.py
new file mode 100644
index 0000000..b72b1f5
--- /dev/null
+++ b/programs/rommon_to_integer.py
@@ -0,0 +1,23 @@
+def roman_to_int(s: str) -> int:
+ roman_dict = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
+ result = 0
+ for i in range(len(s)):
+ if i < len(s) - 1 and roman_dict[s[i]] < roman_dict[s[i+1]]:
+ result -= roman_dict[s[i]]
+ else:
+ result += roman_dict[s[i]]
+ return result
+
+
+'''
+>>> roman_to_int('III')
+3
+>>> roman_to_int('IV')
+4
+>>> roman_to_int('IX')
+9
+>>> roman_to_int('LVIII')
+58
+>>> roman_to_int('MCMXCIV')
+1994
+'''
\ No newline at end of file
diff --git a/programs/sort_dict_by_value.py b/programs/sort_dict_by_value.py
new file mode 100644
index 0000000..481792e
--- /dev/null
+++ b/programs/sort_dict_by_value.py
@@ -0,0 +1,9 @@
+data = {
+ 'one':1,
+ 'two':2,
+ 'four':4,
+ 'three':3
+}
+
+sort_dict = {key:val for key,val in sorted(data.items(),key= lambda x : x[1]) }
+print(sort_dict)
diff --git a/programs/transpose_of_matrix.py b/programs/transpose_of_matrix.py
new file mode 100644
index 0000000..a4b4dfe
--- /dev/null
+++ b/programs/transpose_of_matrix.py
@@ -0,0 +1,22 @@
+class Matrix(object):
+ def __init__(self,mat = None):
+ self.mat = mat
+
+ def get_matrix(self) -> list:
+ return self.mat
+
+ def transpose(self) -> list:
+ if self.mat:
+ try:
+ return list(zip(*self.mat))
+ except Exception as e:
+ return f"Failed to convert transpose because {e}"
+mat = [
+ [1,2,3],
+ [4,5,6],
+ [7,8,9]
+ ]
+
+matrix_obj = Matrix(mat)
+print(f"Original Matrix is : \n {matrix_obj.get_matrix()}")
+print(f"Transpose of above matrix is : \n {matrix_obj.transpose()}")
diff --git a/student_form.py b/student_form.py
new file mode 100644
index 0000000..04cfb0d
--- /dev/null
+++ b/student_form.py
@@ -0,0 +1,46 @@
+"""
+Student Registration Form
+This program collects student details and displays them in a formatted manner.
+"""
+
+def main():
+ """Main function to collect and display student information."""
+
+ print("=" * 60)
+ print("STUDENT REGISTRATION FORM".center(60))
+ print("=" * 60)
+ print()
+
+ # Collecting user input
+ name = input("What is your name? ")
+ reg_number = input("What is your registration number? ")
+ department = input("What is your department? ")
+ faculty = input("What is your faculty? ")
+ course = input("What is your course of study? ")
+ level = input("What is your current level of study? ")
+ programme = input("What is your programme of study? ")
+ state = input("What is your state of residence? ")
+ nationality = input("What is your nationality? ")
+
+ # Displaying the collected information in a formatted form
+ print("\n" + "=" * 60)
+ print("STUDENT DETAILS".center(60))
+ print("=" * 60)
+ print(f"""
+Name: {name}
+Registration Number: {reg_number}
+Department: {department}
+Faculty: {faculty}
+Course of Study: {course}
+Level: {level}
+Programme of Study: {programme}
+State of Residence: {state}
+Nationality: {nationality}
+""")
+ print("=" * 60)
+ print("Thank you for registering!".center(60))
+ print("=" * 60)
+
+
+if __name__ == "__main__":
+ main()