Friday, February 1, 2019

Is Valid Prime

  • Problem Description

    A prime number is an integer greater than 1 that is only divisible by one and itself. Write a function that determines whether or not its parameter is prime, returning True if it is, and False otherwise. 

    Write a main program that reads an integer from the user and displays a message indicating whether or not it is prime. 

    Ensure that the main program will not run if the file containing your solution is imported into another program.

    Refer sample input and output for formatting specification.

    All float values are displayed correct to 2 decimal places.

    All text in bold corresponds to input and the rest corresponds to output
  • CODING ARENA
  • a=int(input())
    k=0
    for i in range(2,a//2+1):
        if(a%i==0):
            k=k+1
    if(k<=0):
        print("TRUE")
    else:
        print("FALSE")
  • Test Case 1

    Input (stdin)
    7
    
    
    Expected Output
    TRUE
  • Test Case 2

    Input (stdin)
    8
    
    
    Expected Output
    FALSE

No comments:

Post a Comment