asked    Rock     2018-10-22       python       55 view        1 Answer

[SOLVED] Please clarify my mistake while doing the dry run

The following code is all correct but I have a doubt. While I am doing the dry run I find in my mind that it should show 2 as NOT a prime number. Someone please clarify how the code is running all good.

num = 4
if num > 1:
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break
   else:
       print(num,"is a prime number")

else:
   print(num,"is not a prime number")

  1 Answer  

        answered    Darcy     2018-10-22      

2 is a prime number, but your code will shows 2 as not a prime number

Here is the fix:

num = 4
if num > 2:
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break
   else:
       print(num,"is a prime number")

elif num = 2
    print(num, "is a prime number")

else:
   print(num,"is not a prime number")




Your Answer





 2018-10-22         Christian

Regex: how to substitute a string with n occurrences of a substring

As a premise, I have an HTML text, with some <ol> elements. These have a start attribute, but the framework I'm using is not capable to interpret them during a PDF conversion. So, the trick I am trying to apply is to add a number of invisible <li> elements at the beginning.As an example, suppose this input text:<ol start="3"> <li>Element 1</li> <li>Element 2</li> <li>Element 3</li></ol>I want to produce this result:<ol> <li style="visibility:hidden"></li> <li style="visibility:hidden"...
 java                     5 answers                     35 view
 2018-10-22         Sid

SpringMVC built by IDEA: No converter found for return value of type

I use IDEA to build a simple RESTful server based on SpringMVC. But @RestController and @ResponseBody can't convert POJO to JSON by jackson JSON.In dispatcher-servlet.xml:<mvc:annotation-driven/>In pom.xml: <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> <version>2.9.5</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> ...
 java                     2 answers                     35 view
 2018-10-22         Dawn

How do I close the download pop in chrome browser when downloading PDF

I am using java selenium to automate my application.I am downloading PDF and parsing.There are multiple test cases with PDF in my application. So once i download first PDF the chrome show a pop at the bottom of browser that file is downloaded with file name so next time when i try to download the second PDF the Download button is below this pop and not able to click on download option.Used isDisplayed method to check status which return false and isEnabled returns true.Tried execution of the PDF testcase in another window it is not working either. Please refer the image for...
 java                     2 answers                     32 view