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
8 changes: 8 additions & 0 deletions Mis Calculator Q4/Addition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from math import ceil

def add(a,b):
# This function returns the addition of two numbers
# The function rounds up the result if it is with decimals
return(ceil(float(a) + float(b)))


6 changes: 6 additions & 0 deletions Mis Calculator Q4/Division.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from math import ceil

def divide(a,b):
# This function returns the division of two numbers
# The function rounds up the result if it is with decimals
return ceil(a / b)
63 changes: 63 additions & 0 deletions Mis Calculator Q4/Mis_Calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Assignment week 4, question 1

from Addition import add
from Multiplication import Multiply
from Substraction import substract
from Division import divide

def greetings_and_instructions():
# Instructions to the user
print('Choose one of the following operations: ')
print('1- For Addition')
print('2- For Subtraction')
print('3- For Multiplication')
print('4- For Division')


print('Welcome to Mis Calculator')
greetings_and_instructions()


while True:
try:
user_choice = int(input('\nYour choice: '))
assert user_choice > 0 and user_choice <= 4
except ValueError:
print('You entered wrong choice, please choose again as displayed in the menu: ')
greetings_and_instructions()
continue
except AssertionError:
print('Your choice is not within the menu, please choose again as displayed in the menu: ')
greetings_and_instructions()
continue

while True:
try:
a = float(input('Enter the first number: '))
b = float(input('Enter the second number: '))
except ValueError:
print('You did not enter a number, please enter a number:\n')
continue
else:
break



if user_choice == 1:
print(a,'+',b ,'=',add(a,b))
elif user_choice == 2:
print(a,'-',b ,'=',substract(a,b))
elif user_choice == 3:
print(a,'*',b ,'=',Multiply(a,b))
elif user_choice == 4:
print(a,'/',b ,'=',divide(a,b))

repeat = input('Do you want to repeat? (Yes), (Y) or (No) (N): ').upper()

if repeat == 'Y' or repeat == 'YES':
greetings_and_instructions()
continue
if repeat != 'Y' or repeat != 'YES':
break

print('Thank you! ')
7 changes: 7 additions & 0 deletions Mis Calculator Q4/Multiplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from math import ceil

def Multiply(a,b):
# This function returns the mulitplication
# of two numbers
# The function rounds up the result if it is with decimals
return ceil(a * b)
6 changes: 6 additions & 0 deletions Mis Calculator Q4/Substraction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from math import ceil

def substract(a,b):
# This function returns the substraction of two numbers
# The function rounds up the result if it is with decimals
return ceil(a - b)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions Q2 alphabet file/A.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
1 change: 1 addition & 0 deletions Q2 alphabet file/B.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
B
1 change: 1 addition & 0 deletions Q2 alphabet file/C.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
1 change: 1 addition & 0 deletions Q2 alphabet file/D.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
D
1 change: 1 addition & 0 deletions Q2 alphabet file/E.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
E
1 change: 1 addition & 0 deletions Q2 alphabet file/F.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
F
1 change: 1 addition & 0 deletions Q2 alphabet file/G.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
G
1 change: 1 addition & 0 deletions Q2 alphabet file/H.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
H
1 change: 1 addition & 0 deletions Q2 alphabet file/I.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I
1 change: 1 addition & 0 deletions Q2 alphabet file/J.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
J
1 change: 1 addition & 0 deletions Q2 alphabet file/K.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
K
1 change: 1 addition & 0 deletions Q2 alphabet file/L.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
L
1 change: 1 addition & 0 deletions Q2 alphabet file/M.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
M
1 change: 1 addition & 0 deletions Q2 alphabet file/N.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
N
1 change: 1 addition & 0 deletions Q2 alphabet file/O.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
O
1 change: 1 addition & 0 deletions Q2 alphabet file/P.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
P
1 change: 1 addition & 0 deletions Q2 alphabet file/Q.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Q
1 change: 1 addition & 0 deletions Q2 alphabet file/R.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
R
1 change: 1 addition & 0 deletions Q2 alphabet file/S.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
S
1 change: 1 addition & 0 deletions Q2 alphabet file/T.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
T
1 change: 1 addition & 0 deletions Q2 alphabet file/U.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
U
1 change: 1 addition & 0 deletions Q2 alphabet file/V.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
V
1 change: 1 addition & 0 deletions Q2 alphabet file/W.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
W
1 change: 1 addition & 0 deletions Q2 alphabet file/X.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
X
1 change: 1 addition & 0 deletions Q2 alphabet file/Y.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Y
1 change: 1 addition & 0 deletions Q2 alphabet file/Z.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Z
30 changes: 30 additions & 0 deletions q1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Assignment week 4, question 1
import string

capital_letters = string.ascii_uppercase
lwoer_case_letters = string.ascii_lowercase


def letters_with_specific_numbers(n):
"""
This function creates a file where all letters
of English alphabet(uppercase and lowercase both)
are listed by specified number of letters on each line.
"""
lst = []
with open("q1.txt", "w") as f:
for i in range(0, len(capital_letters), n):
letter = capital_letters[i : i + n]
lst.append(letter)

f.write("\n".join(lst))
f.write("\n")
lst2 = []
for i in range(0, len(lwoer_case_letters), n):
letter = lwoer_case_letters[i : i + n]
lst2.append(letter)

f.write("\n".join(lst2))


letters_with_specific_numbers(3)
18 changes: 18 additions & 0 deletions q1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ABC
DEF
GHI
JKL
MNO
PQR
STU
VWX
YZ
abc
def
ghi
jkl
mno
pqr
stu
vwx
yz
18 changes: 18 additions & 0 deletions q2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Assignment week_4, question 2
import string
import os


# store the text files in q2 alphabet directory
if os.path.exists("Q2 alphabet file"):
pass
else:
os.mkdir("Q2 alphabet file")

# change the directory to \q2 alphabet file
os.chdir("Q2 alphabet file")
letters = string.ascii_uppercase

for i in letters:
with open(i + ".txt", "w") as f:
f.write(i)
27 changes: 27 additions & 0 deletions q3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Assignment week_4, question 3
from math import gcd


def lcm(*input):
# This function returns the LCM value for 2 or more given inputs
lcmm = input[0]
for i in range(1,len(input)):
lcmm = lcmm * input[i]//gcd(lcmm, input[i])
return lcmm


print("Welcome to LCM calculator: ")

while True:
try:
user_input = []
# take 4 inputs
for i in range(1, 5):
a = int(input("Enter input number " + str(i) + " : "))
user_input.append(a)
except ValueError:
print("Invalid entry, please enter inegers")
continue
else:
print("The LCM for the entered inputs is:", lcm(*user_input))
break