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 Add_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Addition

from math import ceil

def addition (n_1,n_2):

sum= n_1+n_2
return ceil(sum)
13 changes: 13 additions & 0 deletions Answ_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## 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.

import string

with open('letters_file.txt', 'w') as f:
letters=string.ascii_letters
for i,letter in enumerate(letters,1):
f.write(f'{i} {letter}\n') #on every line write number and letter

16 changes: 16 additions & 0 deletions Answ_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## 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
import os

os.mkdir('Letters') #make a directory for alphabet files

os.chdir('Letters') #make the 'Letters' a current directory

letters=string.ascii_uppercase #make a sequence of uppercase letters.
for letter in letters: # loop to creat lettersnamed files
with open(f'{letter}.txt','x'):
pass
32 changes: 32 additions & 0 deletions Answ_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## LCM

# 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 sys #import module sys to get a type of exception
from math import lcm #import lcm



print('Enter 4 numbers.')
try:
a,b,c,d = list(map(int, input('Numbers - ').split())) #input numbers
# print(a,c,d)
except ValueError as e: #to verify input entries
print()
print('Plese enter integer numbers!')
print('Try again!')
# Calculate the least common multiple (L.C.M.) of four numbers
# use lcm (not gcd) function!
print('least common multiple (L.C.M.) of four numbers',lcm(a,b,c,d))


62 changes: 62 additions & 0 deletions Answ_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
## 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 Add_calc import *
from Divis_calc import *
from Mult_calc import *
from Substr_calc import *

actions = {
'/': divis,
'+': addition,
'-': substract,
'*': multipl
}

while True:
try:
print('\n\n Hello to Mis Calculator!\n')
a = float(input('Enter first number -'))
b = float(input('Enter second number -'))


action = input('''Chose the action.
Enter character:
+ for add
- for subtract
* for multiply
/ for divide''')
assert action in actions
print(f'The result is {(actions[action](a,b))}')
except ValueError as e:
print()
print('Enter number only!')
print()
except AssertionError:
print()
print('Unavailable action.')

answer = input('Whould you like to continue? Y or N... ')
if answer.lower() in 'yes':
continue
else:
break
10 changes: 10 additions & 0 deletions Divis_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Division

from math import ceil

def divis (n_1,n_2):
try:
div= n_1/n_2
except ZeroDivisionError:
print('Sorry, it is not possible!')
return ceil(div)
8 changes: 8 additions & 0 deletions Mult_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Multiplication

from math import ceil

def multipl (n_1,n_2):

mult= n_1*n_2
return ceil(mult)
8 changes: 8 additions & 0 deletions Substr_calc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Substraction

from math import ceil

def substract (n_1,n_2):

sub = n_1-n_2
return ceil(sub)
Binary file added __pycache__/Add_calc.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/Divis_calc.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/Mult_calc.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/Substr_calc.cpython-310.pyc
Binary file not shown.