Python - Prime finder/calculator error -


OK, I know my code is very inefficient and is longer than that, but I'm very new to the dragon And there is only one address to perform some basic tasks

  restart = true numtocheck = 2 # to test the number of headings 0 == 0: #forever loop if restart == true: Testnum = 2 # to use 'numtocheck' Varible calculation = numtocheck / testnum if (calculation) .is_integer (): numtocheck = numtocheck + 1 else: testnum = testnum + 1 if numtocheck == testnum: print (numtocheck) # a Key numtocheck = Numtocheck + 1 restart = true: restart = false  

The production is almost completely full of prime, although there are many such that as '35' or '95' Which appear to run code every time. I do not know what is happening, and therefore any help would be greatly appreciated :)

Let's add some debug output and analyze what happens. Firstly it is obviously Python 3, because Python 2 will not execute this code. Fine. I will add some debug output in my code like this:

  restart = true numtocheck = 2 # will be tested to be prime = 0 while i & lt; 150: #not forever loop now :) if restart == true: testnum = 2 # to use 'numtocheck' varible calculation = numtocheck / testnum to test if (count) .is_integer (): numtocheck = numtocheck + 1 else : Testnum = testnum + 1 if numtocheck = = 'Testnum: print (numtocheck) # should be a major numtocheck = numtocheck + 1 restart = True else: restart = False print (' numtocheck% s '% numtocheck) Print (' testnum% Okay, here is the result (I took the number 27 as a good example):  
  Numtocheck 26 testnum 13 numtocheck 27 testnum 13 numtocheck 27 testnum 14 numtocheck 27  

So here we are. You are checking number 26. 26/12 is float, okay, you increase testnum up to 13 and 26/13 that int is hooray. You go to the next digit mark- 27. But forget about testnum var and it's still 13. So you do the test with 27/13, 27/14 and so on 27, and as a result- 27 is a major, because you have lost 27/3 and 27/9 then

 after  <= P>  

And everything will be fine.

sb.append ( "\ n --------------------------"); // एडाप्टर = नए SimpleCursorAdapter (यह, R.layout.custcontview, managedCursor, नई String [] { "संख्या", "type", "तिथि", "DURATION"}, नई पूर्णांक [] {R.id.ccontNo, R.id.ccontName, R.id.ccontType, R.id.textView1}); } Tv.setText (sb); // lv.setAdapter (adapter); // प्रबंधित कैसर। बंद (); }}

मैनिफेस्ट में निम्नलिखित अनुमति जोड़ें

  & Lt; उपयोग-अनुमति एंड्रॉइड: name = "android.permission.READ_CALL_LOG" / & gt; & Lt; उपयोग-अनुमति एंड्रॉइड: name = "android.permission.WRITE_CALL_LOG" / & gt;  

लॉग पुनर्प्राप्त करने के लिए निम्न कोड का उपयोग करें

  सार्वजनिक शून्य getLogsByNumber (स्ट्रिंग [] strNumber) {कर्सर कर्सर = getContentResolver ()। क्वेरी (CallLog.Calls .CONTENT_URI, रिक्त, कॉल लॉग। कॉल। संख्या + "=?", स्ट्रॉनम्बर, ""); If (cursor.moveToFirst ()) {while (cursor.moveToNext ()) {String id = cursor.getString (cursor.getColumnIndex (CallLog.Calls._ID)); स्ट्रिंग संख्या = कर्सर.गेटस्ट्रिंग (कर्सर.टस्टाइनमंडेक्स (CallLog.Calls.NUMBER)); स्ट्रिंग का नाम = कर्सर.गेटस्ट्रिंग (कर्सर.जस्टॉलमैंइंडेक्स (CallLog.Calls.CACHED_NAME)); }}}  
पर क्लिक करें

Comments

Popular posts from this blog

graphviz - size of node with shape=circle -

android - TCP sending with Unity -

properties - C#: How to set default value for a property in a partial class? -