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
  Βad Input on line 12 Azdaghost 5 1,186 Apr-19-2025, 10:22 PM
Last Post: Azdaghost
  interactive process for input and output maiya 1 569 Mar-27-2025, 08:40 AM
Last Post: Gribouillis
  How to revert back to a previous line from user input Sharkenn64u 2 919 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  How to make it so whatever I input into a script gets outputted on a different file spermatozwario 4 1,145 Nov-24-2024, 12:58 PM
Last Post: deanhystad
Question [SOLVED] Same input different output antarling 2 904 Oct-25-2024, 11:28 PM
Last Post: antarling
  I think I need to delete input data because returning to start fails thelad 2 1,089 Sep-24-2024, 10:12 AM
Last Post: thelad
  Input function oldschool 1 723 Sep-14-2024, 01:02 PM
Last Post: deanhystad
  User input with while loops chizzy101010 2 5,331 Aug-25-2024, 06:00 PM
Last Post: chizzy101010
  ValueError: could not broadcast input array from shape makingwithheld 1 2,452 Jul-06-2024, 03:02 PM
Last Post: paul18fr
  email address input jacksfrustration 5 2,357 Jun-26-2024, 08:35 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

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