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
35 changes: 0 additions & 35 deletions README.md

This file was deleted.

13 changes: 13 additions & 0 deletions alphabet.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
abcd
efgh
ijkl
mnop
qrst
uvwx
yzAB
CDEF
GHIJ
KLMN
OPQR
STUV
WXYZ
17 changes: 17 additions & 0 deletions homework_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Question 1
"""Letters for each line
Write a Python program to create a file where all letters of English
alphabet(uppercase and lowercase both) are listed by specified number of letters on each line.
"""

letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

def letters_file_line(n):

with open("alphabet.txt", "w") as f:
for i, letter in enumerate(letters):
f.write(letter)
if (i + 1) % n == 0:
f.write("\n")

letters_file_line(4)
23 changes: 23 additions & 0 deletions homework_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Question 2
Write a Python program to generate 26 text files named A.txt, B.txt, and so on up to Z.txt."""

import string, os # import string and os.path

""" First define a function file_generaters which generates a text file for each letter of the uppercase alphabet. """

def file_generaters():
"""if a directory named "letters" exists and
creates it if it doesn't using the os.makedirs function."""

if not os.path.exists("letters"):
os.makedirs("letters")

"""This for loop will for each leter in the upercase alphabet, defined by string.ascii_uppercase, the code
creates a text file with the name of the letter and writes to the letters as its contents using the with statement
and the open functiion. """

for letter in string.ascii_uppercase:

with open(letter + ".txt", "w") as f:
f.writelines(letter)
file_generaters() # function is called to generate the file names
48 changes: 48 additions & 0 deletions homework_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
### Question 3
"""As a user, I want to use a program which can calculate the least common multiple (L.C.M.)
of four numbers. So that I can find the least common multiple (L.C.M.) of my inputs.

Acceptance Criteria:

Ask user to enter the four numbers.
Use try/except blocks to verify input entries and warn the user for Nan or non numerical inputs.
Calculate the least common multiple (L.C.M.) of four numbers
Use gcd function in module of math
"""

import math

"""The 'main_func' function takes four numbers as input and returns the L.C.M. of these numbers."""
def main_func(num1,num2,num3,num4):
# Code that should be executed when the script is run as the main program
"""The 'math.gcd' function from the 'math' library to calculate the greatest common divisor of two numbers,
which is then used to calculate the L.C.M."""
return num1 * num2 * num3 * num4 // math.gcd(math.gcd(num1, num2), math.gcd(num3, num4))


"""The code is executed only when the script is run as the main program, as
determined by the 'if name == 'main':' statement. Within this block, user input is obtained
for the four numbers and the 'main_func' is called with these inputs. The result is then printed to
the console. Exception handling is used to ensure that the input is a valid number.
"""
if __name__ == '__main__':

while True:
try:
n1 = int(input("Enter the first number:"))
n2 = int(input("Enter the seconde number:"))
n3 = int(input("Enter the third number:"))
n4 = int(input("Enter the fourth number:"))
break
except:
print("Invalid input. Pleass enter a number.")

r = main_func(n1, n2, n3, n4)
print("The least common multiple (L.C.M.) of four numbers:", r)







65 changes: 65 additions & 0 deletions homework_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### Question 4
""""" Mis Calculator
As a user, I want to use a program which can calculate basic mathematical operations. So that I can add, subtract, multiply or divide my inputs.

Acceptance Criteria:

The calculator must support the Addition, Subtraction, Multiplication and Division operations.
Define four functions in four files for each of them, with two float numbers as parameters.
To calculate the answer, use math.ceil() and get the next integer value greater than the result
Create a menu using the print command with the respective options and take an input choice from the user.
Using if/elif statements for cases and call the appropriate functions.
Use try/except blocks to verify input entries and warn the user for incorrect inputs.
Ask user if calculate numbers again. To implement this, take the input from user Y or N."""""


from my_modules import *

# Define the main function
def main_func():

while True:

choice = input(""" Enter Your choice if you want to
for Addition write = add,
for Subtraction= sub,
for Multiplication = mult,
for Division= div,
:> """).lower()

# Try to retrieve the two numbers from the user input
try:
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))

except ValueError:
print("Invalid input. Please enter a number.")
continue

# Check the user's choice and call the appropriate function from the imported module
if choice == "add":
r = add(num1, num2)
print("The result is ", r)
elif choice == "sub":
r = subtract(num1, num2)
print("The result is ", r)
elif choice == "mult":
r = multiply(num1, num2)
print("The result is ", r)
elif choice == "div":
r = divide(num1, num2)
print("The result is ", r)
# If the user's choice is invalid, show an error message and prompt again
else:
print("Invalid choice. Please try again.")
continue

# Ask the user if they want to calculate again
t = input("Do you want to calculate again? (y/n): ").lower()
# If the user doesn't want to calculate again, break out of the loop
if t != 'y':
break

# Execute the main function when the script is run as the main program
if __name__ == "__main__":
main_func()
1 change: 1 addition & 0 deletions letters/A.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions letters/B.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
1 change: 1 addition & 0 deletions letters/C.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
1 change: 1 addition & 0 deletions letters/D.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D
1 change: 1 addition & 0 deletions letters/E.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
E
1 change: 1 addition & 0 deletions letters/F.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
F
1 change: 1 addition & 0 deletions letters/G.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
G
1 change: 1 addition & 0 deletions letters/H.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
H
1 change: 1 addition & 0 deletions letters/I.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I
1 change: 1 addition & 0 deletions letters/J.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
J
1 change: 1 addition & 0 deletions letters/K.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
K
1 change: 1 addition & 0 deletions letters/L.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
L
1 change: 1 addition & 0 deletions letters/M.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
M
1 change: 1 addition & 0 deletions letters/N.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
N
1 change: 1 addition & 0 deletions letters/O.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
O
1 change: 1 addition & 0 deletions letters/P.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
P
1 change: 1 addition & 0 deletions letters/Q.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Q
1 change: 1 addition & 0 deletions letters/R.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
R
1 change: 1 addition & 0 deletions letters/S.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
S
1 change: 1 addition & 0 deletions letters/T.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
T
1 change: 1 addition & 0 deletions letters/U.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
U
1 change: 1 addition & 0 deletions letters/V.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
V
1 change: 1 addition & 0 deletions letters/W.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
W
1 change: 1 addition & 0 deletions letters/X.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
X
1 change: 1 addition & 0 deletions letters/Y.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Y
1 change: 1 addition & 0 deletions letters/Z.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Z
15 changes: 15 additions & 0 deletions my_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# add
def add(a, b):
return a + b

# subtract
def subtract(a, b):
return a - b

# multiply
def multiply(a, b):
return a * b

# divide
def divide(a, b):
return a / b