Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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

def print_alphabet_per_line(n) :

with open("letters.txt", "w") as f:

alphabet = string.ascii_uppercase + string.ascii_lowercase

for i in range(0, len(alphabet), n) :

letters = alphabet[i:i + n] + "\n"
f.writelines(letters)




print_alphabet_per_line(5)



17 changes: 17 additions & 0 deletions 2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Write a Python program to generate 26 text files named A.txt, B.txt, and so on up to Z.txt.


import string

def create_files_A_to_Z () :

A_to_Z = string.ascii_uppercase

for x in A_to_Z :
#print (x)
with open(x + ".txt", "w") as f:
f.writelines ("")


create_files_A_to_Z()

55 changes: 55 additions & 0 deletions 3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
""" 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
"""

from math import gcd
from functools import reduce
import math


def calc_GCD (n1, n2):

return (n1 * n2) // math.gcd(n1, n2)

def calc_LCM (*args):

return reduce(calc_GCD, args) # using recursion with reduce()



try:

n_one = int(input("enter number 1: "))
n_two = int(input("enter number 2: "))
n_three = int(input("enter number 3: "))
n_four = int(input("enter number 4: "))

except ValueError :

print ("You used a non numerical input!")

else:

#gcd = math.gcd( math.gcd(n_one, n_two) , math.gcd(n_three, n_four) )
#print (gcd)

lcm = calc_LCM ( n_one , n_two , n_three , n_four )

print ("the least common multiple (L.C.M.) is: " , end="")
print (lcm)



# for testing - 12 15 75 32 . LCM = 2400






53 changes: 53 additions & 0 deletions 4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
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 user_choosen_option 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 func_add import *
from func_divide import *
from func_multiply import *
from func_subtract import *


while True:

print("What do you want to do: ")
print("(a) add")
print("(s) subtract")
print("(m) multiply")
print("(d) divide")

user_choosen_option = input("Enter first letter... (a)dd, (s)ubtract, (m)ultiply, or (d)ivide: ")

try:
num1 = float(input("enter the first number: "))
num2 = float(input("enter the second number: "))
if user_choosen_option == 'a':
print("result: ", add(num1, num2))

elif user_choosen_option == 's':
print("result: ", subtract(num1, num2))

elif user_choosen_option == 'm':
print("result: ", multiply(num1, num2))

elif user_choosen_option == 'd':
print("result: ", divide(num1, num2))

except ValueError:
print("there's an input error")

calculate_again = input("do you want to calculate something else? (y)es or (n)o? ")
if calculate_again != "y":
break
4 changes: 4 additions & 0 deletions func_add.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import math

def add(a, b):
return math.ceil(a + b)
5 changes: 5 additions & 0 deletions func_divide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import math

def divide(a, b):
return math.ceil(a / b)

5 changes: 5 additions & 0 deletions func_multiply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import math

def multiply(a, b):
return math.ceil(a * b)

4 changes: 4 additions & 0 deletions func_subtract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import math

def subtract(a, b):
return math.ceil(a - b)