Python Forum
Help with try and open 6.txt file and print as perfect or not
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with try and open 6.txt file and print as perfect or not
#1
This is the output I get in quotes with the below python code, however 6 is in the 6.txt file. How can I determine by print output if 6 is a perfect number or not? I know it is a perfect number!

"The number is not a Perfect number!
None"



Please Help I'm on to something big with easily determining Mersenne Prime Numbers. Once I have the below code fixed I can open large perfect numbers and then with my other py file I can differentiate between what numbers are perfect and not. The other code I will post here too after this is resolved and I will explain how its done. My other code is super fast at finding large perfect numbers!




KB = 1024
MB = 1024 * 1024
 
def perfect_number(file):
    
    for s in file:
        n = int(s)
        
sum1 = 0
def n():
 for i in range(1, n):
    if(n % i == 0):
        sum1 = sum1 + i
if (sum1 == n):
    print ("The number is a Perfect number!" )
else:
    print("The number is not a Perfect number!")
 
if __name__ == '__main__':
    with open('6.txt', buffering=1*MB) as bigggg:
        dr = file_perfect_number(bigggg)
    print(dr)
Reply


Messages In This Thread
Help with try and open 6.txt file and print as perfect or not - by Pleiades - Dec-31-2018, 09:48 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open/save file on Android frohr 0 363 Jan-24-2024, 06:28 PM
Last Post: frohr
  file open "file not found error" shanoger 8 1,272 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Are there errors in the code for my coin toss systems? Matlibplot is too perfect . Coolkat 0 412 Nov-13-2023, 11:54 AM
Last Post: Coolkat
  How can i combine these two functions so i only open the file once? cubangt 4 919 Aug-14-2023, 05:04 PM
Last Post: snippsat
  Start print a text after open an async task via button Nietzsche 0 736 May-15-2023, 06:52 AM
Last Post: Nietzsche
  I cannot able open a file in python ? ted 5 3,540 Feb-11-2023, 02:38 AM
Last Post: ted
  testing an open file Skaperen 7 1,434 Dec-20-2022, 02:19 AM
Last Post: Skaperen
  Saving the print result in a text file Calli 8 1,908 Sep-25-2022, 06:38 PM
Last Post: snippsat
  I get an FileNotFouerror while try to open(file,"rt"). My goal is to replace str decoded 1 1,433 May-06-2022, 01:44 PM
Last Post: Larz60+
  failing to print not matched lines from second file tester_V 14 6,238 Apr-05-2022, 11:56 AM
Last Post: codinglearner

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020