Python Forum
How do I create a user input for three integers in a range or just the stop input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I create a user input for three integers in a range or just the stop input
#1
Below is the code which shows Prime numbers and Mersenne Prime Numbers. It also spits out the last digit of a long number which could be prime or not. I would like the number range, "stop" to be used for user input. Any help thank you.
code part which I don't understand how to incorporate user input:

for num in range(3,30,2):
import math
# Python program to check if the input number is prime or not
  
  
def isPrime(num):
    for i in range(2, int(math.sqrt(num)+1)):
        if num % i == 0: 
            return False;
    return num>1;
  
print 2
print 3
print 3
print ("______________")
for num in range(3,30,2):
                 if isPrime(num):
                    if all(num%i!=0 for i in range(3,int(math.sqrt(num))+1, 2)):
          
                        print num
                        print  ((2**num-1)*(2**num)/2)/(2**num)*2+1
                        print ((((2**num-1)*(2**num)/2)/(2**num)*2+1+1)%10)-1
                        print ("______________")
Reply
#2
you need to use input statement:
num = int(input('Enter a number to test: '))
print(isPrime(num))
Reply
#3
Thanks a great deal now I can make it into a user friendly program for people to use.

Here's the final code:


import math
# Python program to check if the input number is prime or not
from itertools import count   
  
def isPrime(num):
    for i in range(2, int(math.sqrt(num)+1)):
        if num % i == 0: 
            return False;
    return num>1;
   


num = int(input('Enter a number to test: '))
for num in range(3,num,2):
            if isPrime(num):
                if all(num%i!=0 for i in range(3,int(math.sqrt(num))+1, 2)):
                        print 2
                        print 3
                        print 3
                        print ("______________")
                        print num
                        print  ((2**num-1)*(2**num)/2)/(2**num)*2+1
                        print ((((2**num-1)*(2**num)/2)/(2**num)*2+1+1)%10)-1
                        print ("______________")
Reply
#4
A couple of things about python coding style:
indentation should be four spaces (not tab) per level.
Camel case is frowned upon for method and function names, but can (should be?) used for class names.
See: https://www.python.org/dev/peps/pep-0008/
There is a program you can download to check your code:
pip install pycodestyle
To use, from command line:
pycodestyle modulename.py
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Waiting for input from serial port, then move on KenHorse 3 1,074 Apr-17-2024, 07:21 AM
Last Post: DeaD_EyE
  Help with to check an Input list data with a data read from an external source sacharyya 3 410 Mar-09-2024, 12:33 PM
Last Post: Pedroski55
  difference between forms of input a list to function akbarza 6 1,037 Feb-21-2024, 08:02 PM
Last Post: bterwijn
  pyaudio seems to randomly halt input. elpidiovaldez5 2 378 Jan-22-2024, 09:07 AM
Last Post: elpidiovaldez5
  Receive Input on Same Line? johnywhy 8 727 Jan-16-2024, 03:45 AM
Last Post: johnywhy
  manually input data jpatierno 0 346 Nov-10-2023, 02:32 AM
Last Post: jpatierno
  Using string input for boolean tronic72 3 702 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
  problem in using input command akbarza 4 1,134 Oct-19-2023, 03:27 PM
Last Post: popejose
  problem in entering address of a file in input akbarza 0 654 Oct-18-2023, 08:16 AM
Last Post: akbarza
  Input network device connection info from data file edroche3rd 6 1,048 Oct-12-2023, 02:18 AM
Last Post: edroche3rd

Forum Jump:

User Panel Messages

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