SLC S21W5 : Mastering File Handling in Python and Qt Designer Part 1

in #dynamicdevs-s21w52 days ago (edited)

Black Gold Elegant Jewelry Logo_20241129_083747_0000.png

edited with canva

Hello friends and welcome to my article in the SLC: S21/W5 in this great task I would br more than ready to put in the work and bring forth a formidable result after work.


The program calculates Mersennes numbers within a specified range using PyQt5. A mersenne number defined as (M=2nN-1) where (N) is prime number

Working with PyQt5 this time creating more quality out of it, first program calculates Mersennes numbers within range. Input (A) is quite greater than 2 in first input, second input (B) is quite greater than than 2 and (A) respectively. All things being equal all variable inputs are reasonably less than 50,000 Using built-in function, we create file mersennes.txt to analyse and bring results to the limelight.


Screenshot_20241129-065031.png
DT design on PyQt5

For the PyQt5 program to be at optimum performance we use Inbuilt Function to import required modules. We add math which aids in working mathematical functions. The default remainder has been totally created to determine prime numbers. This anonymous number added must satisfy certain conditions which are; must be greater than 2 and also the sqaute root of anonymous numbers must be observed.

Calculating Mersennes of the unknown prime number, we note our input being A and B needs to be validated with visible range say; 2<A<aB<50000 Calculating Mersennes, we use formal M=2nN-1 This point we filter primes to generate needed Mersennes number. Mersennes number generated, we go ahead looking up how to create decode and analyze data on files.


Screenshot_20241129-065105_3.pngparentScreenshot_20241129-065105_2.pngsource

calculating mersennes of unknown prime number


In-built function is available to help create file.next a loop to write data in file. In this case will be a result of calculations of received Mersennes numbers. Errors are definitely a function of these programs so we try hard to again perfection. We intricately look on to spot display results. In doing so we have mersennes.txt We tabulate with rows and column and thus result above.


Program calculates prime factors of a given number and saves result in a text file named factors.txt

Going ahead for prime factors of numbers input, saving results on text file.

Screenshot_20241129-072456.png
calculating for unknown prime factors

This function calculates to give list of prime factors would be priority, computation process would be observed with a number which would be a divisor of 2 which is the least prime number. The while loop is used to check every possible divisor from number input. Input process is gotten using function above to get out a lot of prime factors if duly validated.

Conversion of list of strings would definitely be by using the join () function, trying alternative methods. To gain better understanding we going to use loop to iterate list and concentrate from strings. The "x" is separate factors just to apply x if a prime factor is noticed.

Screenshot_20241129-072713.pngparentScreenshot_20241129-072807.pngsource

spotting and saving text file



This programmed validated 13 digits codes based on special criteria, manages them using a file named codes.txt

Screenshot_20241129-072824.png
validating 13-digit codes based on specific criteria

Program is broken into smaller sectors, to validate, save, encode and decode file results. There are special modes operandi to be recognized in this special task. The conscious decision of putting 13 digit numbers recognizing the first three digits to represent prime numbers, middle five digits to be converted to binary and containing precisely above 6 zeros. The last five digits must be indeed divisible by first three digits.

A junction to validate input, starting with codes checking for input length, which must be 13 digits, we check first 3 digits from prime numbers using is_prime We immediately create and write data on file, Data to write is passed as parameter for the save_code function the real_code function to read all data on file.

Moreso, the VERIFY CODE Function is triggered by verify button, input checked by making use of Validate_code Function if input is valid, we go to iterate to check input if it has been written and saved on file.

Conditionally, if input is saved it goes a long way override and add new codes, if not an error from validate_code erupts next to function which is triggered by display button, reading save_code from file. We sort code when radio button is checked and populates result_sheet with sorted codes.

Screenshot_20241129-072924.pngsourcecode management using code.txt

This program identifies Smith numbers within a user-defined range through graphical user interface, A Smith number is composite number where sum of its digits equals sum of digits of prime factors.

We import necessary modules for task, using images for Q7 design of interfaces, to calculate Smith number, we check if number is a prime number and sum up to get prime factor. We make sure first input (a) is at least 4 and also importantly, less than or equal to second input (b) Try to break whole process into smaller factors for easy validation and code understanding.

Screenshot_20241129-072959.png
Ranging Smith Numbers

A smith number must be able to validate a prime number before getting its prime factor,we compare sum of digits of numbers with sum of its prime factors. If they tally, most likely it is a Smith number we can actually find the smith number within range (a) and input (b)

Screenshot_20241129-073204.pngsourcelooping number unveils smith number!

Smith number will be obtained by looping through numbers within range to get numbers that return true to be Smith Numbers function process was a process breakdown of functions to achieve smith number within range. RESET and QUIT Function are similar and do not have a lot change we specify program intended.

Cc;
@kouba01

I have concluded the quest and invite @josepha @simonnwigwe @dove11 @chant to join challenge