Mastering File Handling in Python and Qt Designer Part 1.

in Steem Nations8 hours ago

Assalam o Alaikum Everyone I hope all of you are fine and happy in your life. Here is my participation in the steemit contest. This is Part 1 participation. This contest was organised by @kouba01. The contest is about learning a Python programming language. Python is a huge market. We can do almost all things with Python programming language. #steemexclusive

  • Task 1(Mersenne numbers)

image.png

I used four major functions in my code. The first one is (def is_prime(num)) :) to find out the number is prime or not. It work with Numbers less than or equal to 1 are not prime. Numbers 2 and 3 are prime. For larger numbers, it checks divisibility by all numbers up to (Square,num), Second one is (def calculate_mersenne(self):) to find out all Mersenne numbers in the range and saves them to a file. Take input from user both valu and ensure both value are correct (2<A<B<50000), then here is formula that I used m = (2 ** n) - 1(2 power of n). I use file.write to save data in file. This is third function (def display_results(self):) for display result in UI. After the result, the File is saved in the dictionary.

image.png

image.png

image.png

image.png

  • Task 2(Prime number)

Smallest prime number is 2 and make two variable the use nested while loop for check input is prime or not. UI is same for all tasks.

image.png

image.png

image.png

image.png

  • Task 3(validate 13-digit)

This task was more difficult for me to do, but finally, I did it perfectly. It was more confusing because there were too many conditions on a single input. This is the main function(def validate_code(code):) for checking the validity of input 13 digits. First of all check code I length is 13 or not then three conditions. first three digits, binary number, and last five divisible by first three. I use this function(def add_code(code):) for check if input code is already exit or not. ALso I add functionality of ascending and descending 13 digit code order.

image.png

image.png

image.png

image.png

image.png

image.png

  • Task 4(Smith numbers):

This task finds Smith numbers. The def is_prime() function checks if a number is prime, and def sum_of_digits() calculates the sum of a number's digits.def is_smith_number() is the main logic that checks and find all Smith numbers in the given range. The results are saved in the txt file and def load_smith_numbers() loads the data from the file. These are major functions for this task.

image.png

image.png

image.png

All the task have done. Twiter is banned in Pakistan so I cannot share on Twitter. Thank you so much for reading this blog. I invite @ammar2021,@teukuipul87 and @isha-rehman to participate in this contest.

Sort:  
Loading...