Mastering File Handling in Python and Qt Designer Part 1
Assalamualaikum my fellows I hope you will be fine by the grace of Allah. Today I am going to participate in the steemit learning challenge season 21 week 5 by @kouba01 under the umbrella of steemit team. It is about Mastering File Handling in Python and Qt Designer Part 1. Let us start exploring this week's teaching course.
Task 1 - Claculation of Mersenne Numbers
According to the requirement of the task 1 to develop an application to calculate the Mersenne numbers I have added the following things in the GUI.
A label at the top to display the name and the next label to represent A and another label to represent B for the user. They will make the user interface easy to understand.
I have added 2 input fields to get input from the user. First input will be used to get input from the user for the variable A and the other will be used to get the input from the for the variable B.
There are three buttons in the application to perform the operations. One button is Decompose to calculate and find the prime factors of the given number. The other button Reset is to clear the input field and the output. Another button Display to display the Mersenne numbers found in the range.
First of all I have imported the GUI mersenne_numbers.ui
whcih I created in the Designer. The application is running without any error. You can see that when I am giving two numbers and clicking on the Mersenne button it is collecting the mersenne numbers within the range. And then the display button is displaying the numbers.
But before this it is checking the input and valiadting it and if it meets all the codnitions then it proceeds the Mersenne Number application and find the mersenne numbers otherwise it is showing errors on the screen while informing which type of error is happening. It validates the input by the following this criteria:
- Invalid Input, A field is empty.
- Range must satisfy 2 < A < B < 50000.
If the input breaches these conditions then it will display the relevant error on the screen.
This is the mersenne.txt
file where I am saving the Mersenne Numbers found in the given interval and then getting data from this file.
So we can use this application to find the Mersenne numbers between the given range but we need to keep in mind the criteria while giving the input.
Task 2 - Claculation of Prime Factors
According to the requirement of the task 2 to develop an application to calculate the Prime Numbers I have added the following things in the GUI.
A label at the top to display the name and the next label to represent Type a number for the user. It will make the user interface easy to understand.
I have added an input field to get input from the user. The input will be used to get input from the user for the variable number.
There are two buttons in the application to perform the operations. One button is Decompose to convert the number into its factors. The other button Reset is to clear the input field and the output. Another button Display to display the prime factors of the number given by the user.
First of all I have imported the GUI prime_factors.ui
which I created in the Designer. The application is running without any error. You can see that when I am giving a number and clicking on the decompose button it is decomposing the number into its prime factors. And then the display button is displaying the prime factors.
But before this it is checking the input and valiadting it and if it meets all the codnitions then it proceeds the Prime Factors application and decompose the given number and then return the prime factors of the number otherwise it is showing errors on the screen while informing which type of error is happening. It validates the input by the following this criteria:
- Input field is empty. Please enter a number.
- Please enter a positive integer.
If the input breaches these conditions then it will display the relevant error on the screen.
This is the factors.txt
file where I am saving the prime factors of the given number. And then this file is returning the factors without any probelm.
So we can use this application to find the prime factors of the number by decomposing it but we need to keep in mind the criteria while giving the input.
Task 3 - Application for Validation of Recharge Codes
According to the requirement of the task 3 to develop an application to validate the recharge codes based on the specific criteria I have added the following things in the GUI.
A label at the top to display the name and the next label to represent Enter your code for the user. It will make the user interface easy to understand.
I have added an input field to get input from the user. The input field will be used to get input from the user in the form of the 13 digit code. There is another input field as well but this is for to display the instruction for the code.
There are four buttons in the application to perform the operations. One button is Verify to validate the code. The other button Reset is to clear the input field and the output. Another button Display Codes to display therecharge codes in the output area. There is a Close button to close the application.
In order to sort the codes in the descending order there is a radio button.
First of all I have imported the GUI recharge_codes.ui
which I created in the Designer. The application is running without any error. You can see that when I am giving a number and clicking on the Verify button it is validating the eneterd code.
But before this it is checking the input and valiadting it and if it meets all the codnitions then it proceeds the recharge codes application and validate the given code and then return the output otherwise it is showing errors on the screen while informing which type of error is happening. It validates the input by the following this criteria:
- Code must of 13 digits long.
- The first three digits must be a prime number.
- Middle five digits must contain more than eight zeros in binary.
- The last five digits must be divisible by the first three digits.
- The code is already in use.
If the input breaches these conditions then it will display the relevant error on the screen.
- When the code is valid it inofrms that the code has been saved successfully.
Here is the output of the application where different codes are visible in the output field.
This is the Codes.txt
file where I am saving the valid codes and then getting data from this file and validating each code if the new code already exists or not.
So we can use this application to validate the recharge code by implementing the specific criteria as defined above and if the code breaches it then it informs the user about the probelm in the code.
Task 4 - Application to Find Smith Numbers
According to the requirement of the task 4 to develop an application to find the smith numbers from the given interval of a
and b
I have added the following things in the GUI.
A label at the top to display the header image and the next label to represent Find Smith numbers in the interval [a,b]:. Then there are two further labels one for the Terminal a (integer>=4): and the other label for the display of Terminal b (integer>=a): It will make the user interface easy to understand.
I have added 2 input fields to get input from the user. The input field will be used to get input from the user for the terminal a and terminal b. There is another input field as well but this is for to display the Smith Numbers.
There are three buttons in the application to perform the operations. One button is Find to filter the Smith Numbers from the given interval. The other button Reset is to clear the input field and the output. There is a Close button to close the application.
First of all I have imported the GUI smith_numbers.ui
which I created in the Designer. The application is running without any error. You can see that when I am an interval and clicking on the Find button it is finding the Smith Numbers and displaying them.
But before this it is checking the input and valiadting it and if it meets all the codnitions then it proceeds the Smith Numbers finding application and then return the output otherwise it is showing errors on the screen while informing which type of error is happening. It validates the input by the following this criteria:
- Invalid input.
- Invalid range. Ensure 4 ≤ a ≤ b.
If the input breaches these conditions then it will display the relevant error on the screen.
Here is the output of the application where the Smith Numbers are visible within the given range.
This is the SmithNumbers.txt
file where I am saving the Smith Numbers found in the given interval and then getting data from this file.
So we can use this application to filter out the Smith Numbers within the given range or interval by following the specific rules for the interval and if the code breaches it then it informs the user about the probelm in the code.
I invite @wilmer1988, @josepha, @ripon0630 to join this learning challenge.