How do I create a user input for three integers in a range or just the stop input - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How do I create a user input for three integers in a range or just the stop input (/thread-14270.html) |
How do I create a user input for three integers in a range or just the stop input - Pleiades - Nov-22-2018 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 ("______________") RE: How do I create a user input for three integers in a range or just the stop input - Larz60+ - Nov-22-2018 you need to use input statement: num = int(input('Enter a number to test: ')) print(isPrime(num)) RE: How do I create a user input for three integers in a range or just the stop input - Pleiades - Nov-22-2018 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 ("______________") RE: How do I create a user input for three integers in a range or just the stop input - Larz60+ - Nov-22-2018 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 pycodestyleTo use, from command line: pycodestyle modulename.py |