Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "C:\Users\Jacob Bode\PycharmProjects\Test\venv\Scripts\python.exe" "C:\Program Files\JetBrains\PyCharm Community Edition 2019.2.1\helpers\pydev\pydevconsole.py" --mode=client --port=63662
- import sys; print('Python %s on %s' % (sys.version, sys.platform))
- sys.path.extend(['C:/Pycharm Projects'])
- PyDev console: starting.
- Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 32 bit (Intel)] on win32
- >>> from math import sqrt
- ... def prime_tester_with_input():
- ...
- ... is_prime = True
- ...
- ... x = input("What number would you like to test?")
- ...
- ... x = abs(int(x))
- ...
- ... if x > 1:
- ...
- ... for i in range(2, x):
- ...
- ... print("Does " + str(i) + " go into " + str(x) + "?")
- ...
- ... if x % i == 0:
- ...
- ... print("Yes")
- ...
- ... is_prime = False
- ...
- ... break
- ...
- ... else:
- ...
- ... print("No")
- ...
- ... elif x == 1:
- ...
- ... print("1 is a prime number")
- ...
- ... else:
- ...
- ... print("0 is neither prime nor composite")
- ...
- ... if is_prime:
- ...
- ... print(str(x) + " is prime")
- ...
- ... else:
- ...
- ... print(str(x) + " is not prime")
- ...
- ... def prime_tester(x):
- ...
- ... if int(x) != x:
- ...
- ... print("Decimals cannot be prime or composite")
- ...
- ... else:
- ...
- ... is_prime = True
- ...
- ... absolute_valued = abs(int(x))
- ...
- ... if absolute_valued > 1:
- ...
- ... for i in range(2, absolute_valued):
- ...
- ... if x % i == 0:
- ...
- ... is_prime = False
- ...
- ... break
- ...
- ... if is_prime:
- ...
- ... print(str(x) + " is prime")
- ...
- ... else:
- ...
- ... print(str(x) + " is composite")
- ...
- ... elif absolute_valued == 1:
- ...
- ... print(str(x) + " is a prime number")
- ...
- ... else:
- ...
- ... print("0 is neither prime nor composite")
- ...
- ... def number_info():
- ...
- ... num = float(input("What number would you like the information for? "))
- ...
- ... even_tester(num)
- ...
- ... prime_tester(num)
- ...
- ... square_root_finder(num)
- ...
- ... x_squared(num)
- ...
- ... def even_tester(x):
- ...
- ... if int(x) != x:
- ...
- ... print("Decimals are neither even or odd")
- ...
- ... else:
- ...
- ... is_even = False
- ...
- ... if x % 2 == 0:
- ...
- ... is_even = True
- ...
- ... if is_even:
- ...
- ... print(str(x) + " is even")
- ...
- ... else:
- ...
- ... print(str(x) + " is odd")
- ...
- ... def x_squared(x):
- ...
- ... square = x ** 2
- ...
- ... print("The square of " + str(x) + " is " + str(square))
- ...
- ... def square_root_finder(x):
- ...
- ... if x >= 0:
- ...
- ... square_root = sqrt(x)
- ...
- ... print("The square root of " + str(x) + " is " + str(square_root))
- ...
- ... else:
- ...
- ... print("Negative numbers cannot have square roots")
- ...
- >>> def factor_finder(x):
- ... factors = [
- ...
- ... ]
- ... for i in range(0,x):
- ... if x % i == 0:
- ... factors.append(i)
- ... print(factors)
- ...
- ...
- ...
- >>> factor_finder(5)
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- File "<input>", line 6, in factor_finder
- ZeroDivisionError: integer division or modulo by zero
- >>> def factor_finder(x):
- ... factors = [
- ...
- ... ]
- ... for i in range(1,x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... print(factors)
- ...
- >>> factor_finder(5)
- [1, 5]
- >>>
- >>> factor_finder(4)
- [1, 2, 4]
- >>> def factor_finder(x):
- ... factors = [
- ...
- ... ]
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... print("The factors of " + str(x) + " are " + factors)
- ...
- >>> factor_finder(4)
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- File "<input>", line 8, in factor_finder
- TypeError: can only concatenate str (not "list") to str
- >>> def factor_finder(x):
- ... factors = [
- ... ]
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... print("The factors of " + str(x) + " are " + str(factors))
- ...
- >>> factor_finder(4)
- The factors of 4 are [1, 2, 4]
- >>> def number_info():
- ... num = float(input("What number would you like the information for? "))
- ... even_tester(num)
- ... prime_tester(num)
- ... square_root_finder(num)
- ... x_squared(num)
- ... factor_finder(num)
- ...
- >>> number_info()
- What number would you like the information for? >? 5
- 5.0 is odd
- 5.0 is prime
- The square root of 5.0 is 2.23606797749979
- The square of 5.0 is 25.0
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- File "<input>", line 7, in number_info
- File "<input>", line 4, in factor_finder
- TypeError: 'float' object cannot be interpreted as an integer
- >>> def factor_finder(x):
- ... if int(x) == x:
- ... x = int(x)
- ... else:
- ... print("Decimals do not have any factors")
- ... factors = [
- ... ]
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... print("The factors of " + str(x) + " are " + str(factors))
- ...
- >>> number_info()
- What number would you like the information for? >? 5
- 5.0 is odd
- 5.0 is prime
- The square root of 5.0 is 2.23606797749979
- The square of 5.0 is 25.0
- The factors of 5 are [1, 5]
- >>> number_info()
- What number would you like the information for? >? 3.4
- Decimals are neither even or odd
- Decimals cannot be prime or composite
- The square root of 3.4 is 1.8439088914585775
- The square of 3.4 is 11.559999999999999
- Decimals do not have any factors
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- File "<input>", line 7, in number_info
- File "<input>", line 8, in factor_finder
- TypeError: 'float' object cannot be interpreted as an integer
- >>> def factor_finder(x):
- ... if int(x) == x:
- ... x = int(x)
- ... factors = [
- ... ]
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... print("The factors of " + str(x) + " are " + str(factors))
- ... else:
- ... print("Decimals do not have any factors")
- ...
- >>> number_info()
- What number would you like the information for? >? 3.5
- Decimals are neither even or odd
- Decimals cannot be prime or composite
- The square root of 3.5 is 1.8708286933869707
- The square of 3.5 is 12.25
- Decimals do not have any factors
- >>> def factor_finder(x):
- ... if int(x) == x:
- ... x = int(x)
- ... factors = [
- ... ]
- ... if x > 0:
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... print("The factors of " + str(x) + " are " + str(factors))
- ... elif x == 0:
- ... print("Zero does not have any factors")
- ... else:
- ... x = abs(x)
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... opposite = 0 - i
- ... factors.append(opposite)
- ... print("The factors of " + str(x) + " are " + str(factors))
- ... else:
- ... print("Decimals do not have any factors")
- ...
- >>> number_info()
- What number would you like the information for? >? 5
- 5.0 is odd
- 5.0 is prime
- The square root of 5.0 is 2.23606797749979
- The square of 5.0 is 25.0
- The factors of 5 are [1, 5]
- >>> number_info()
- What number would you like the information for? >? 1
- 1.0 is odd
- 1.0 is a prime number
- The square root of 1.0 is 1.0
- The square of 1.0 is 1.0
- The factors of 1 are [1]
- >>> def factor_finder(x):
- ... if int(x) == x:
- ... x = int(x)
- ... factors = [
- ... ]
- ... if x > 0:
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... print("The factors of " + str(x) + " are " + str(factors))
- ... elif x == 0:
- ... print("Zero does not have any factors")
- ... else:
- ... x = abs(x)
- ... for i in range(1, x + 1):
- ... if x % i == 0:
- ... factors.append(i)
- ... opposite = 0 - i
- ... factors.append(opposite)
- ... print("The factors of " + str(x) + " are " + str(factors))
- ... else:
- ... print("Decimals do not have any factors")
- ...
- >>> number_info()
- What number would you like the information for? >? 0
- 0.0 is even
- 0 is neither prime nor composite
- The square root of 0.0 is 0.0
- The square of 0.0 is 0.0
- Zero does not have any factors
- >>> number_info()
- What number would you like the information for? >? -1
- -1.0 is odd
- -1.0 is a prime number
- Negative numbers cannot have square roots
- The square of -1.0 is 1.0
- The factors of 1 are [1, -1]
- >>> number_info()
- What number would you like the information for? >? -5
- -5.0 is odd
- -5.0 is prime
- Negative numbers cannot have square roots
- The square of -5.0 is 25.0
- The factors of 5 are [1, -1, 5, -5]
- >>> number_info()
- What number would you like the information for? >? 15
- 15.0 is odd
- 15.0 is composite
- The square root of 15.0 is 3.872983346207417
- The square of 15.0 is 225.0
- The factors of 15 are [1, 3, 5, 15]
- >>> number_info()
- What number would you like the information for? >? -15
- -15.0 is odd
- -15.0 is composite
- Negative numbers cannot have square roots
- The square of -15.0 is 225.0
- The factors of 15 are [1, -1, 3, -3, 5, -5, 15, -15]
- >>> number_info()
- What number would you like the information for? >? -144
- -144.0 is even
- -144.0 is composite
- Negative numbers cannot have square roots
- The square of -144.0 is 20736.0
- The factors of 144 are [1, -1, 2, -2, 3, -3, 4, -4, 6, -6, 8, -8, 9, -9, 12, -12, 16, -16, 18, -18, 24, -24, 36, -36, 48, -48, 72, -72, 144, -144]
- >>> def number_info():
- ... choice = input("Would you like to know"
- ... "1: If it's even/odd"
- ... "2: If it's prime/composite"
- ... "3: The square root"
- ... "4: The square of the number"
- ... "5: The factors of the number"
- ... "6: All of the above)"
- ... num = float(input("What number would you like the information for? "))
- ... even_tester(num)
- ... prime_tester(num)
- ... square_root_finder(num)
- ... x_squared(num)
- ... factor_finder(num)
- ...
- File "<input>", line 9
- num = float(input("What number would you like the information for? "))
- ^
- SyntaxError: invalid syntax
- >>> def number_info():
- ... choice = input("Would you like to know"
- ... "1: If it's even/odd"
- ... "2: If it's prime/composite"
- ... "3: The square root"
- ... "4: The square of the number"
- ... "5: The factors of the number"
- ... "6: All of the above")
- ... num = float(input("What number would you like the information for? "))
- ... even_tester(num)
- ... prime_tester(num)
- ... square_root_finder(num)
- ... x_squared(num)
- ... factor_finder(num)
- ...
- >>> number_info()
- Would you like to know1: If it's even/odd2: If it's prime/composite3: The square root4: The square of the number5: The factors of the number6: All of the above>? 6
- What number would you like the information for? >? 6
- 6.0 is even
- 6.0 is composite
- The square root of 6.0 is 2.449489742783178
- The square of 6.0 is 36.0
- The factors of 6 are [1, 2, 3, 6]
- >>> def number_info():
- ... choice = input("Would you like to know "
- ... "1: If it's even/odd "
- ... "2: If it's prime/composite "
- ... "3: The square root "
- ... "4: The square of the number "
- ... "5: The factors of the number "
- ... "6: All of the above ")
- ... num = float(input("What number would you like the information for? "))
- ... even_tester(num)
- ... prime_tester(num)
- ... square_root_finder(num)
- ... x_squared(num)
- ... factor_finder(num)
- ...
- >>> number_info()
- Would you like to know 1: If it's even/odd 2: If it's prime/composite 3: The square root 4: The square of the number 5: The factors of the number 6: All of the above >? 5
- What number would you like the information for? >? 5
- 5.0 is odd
- 5.0 is prime
- The square root of 5.0 is 2.23606797749979
- The square of 5.0 is 25.0
- The factors of 5 are [1, 5]
- >>> def number_info():
- ... num = float(input("What number would you like the information for? "))
- ... choice = input("Would you like to know "
- ... "1: If it's even/odd "
- ... "2: If it's prime/composite "
- ... "3: The square root "
- ... "4: The square of the number "
- ... "5: The factors of the number "
- ... "6: All of the above ")
- ... if choice == 1:
- ... even_tester(num)
- ... elif choice == 2:
- ... prime_tester(num)
- ... elif choice == 3:
- ... square_root_finder(num)
- ... elif choice == 4:
- ... x_squared(num)
- ... elif choice == 5:
- ... factor_finder(num)
- ... elif choice == 6:
- ... even_tester(num)
- ... prime_tester(num)
- ... square_root_finder(num)
- ... x_squared(num)
- ... factor_finder(num)
- ... else:
- ... print("That wasn't an option")
- ...
- >>> number_info()
- What number would you like the information for? >? 5
- Would you like to know 1: If it's even/odd 2: If it's prime/composite 3: The square root 4: The square of the number 5: The factors of the number 6: All of the above >? 6
- That wasn't an option
- >>> def number_info():
- ... num = float(input("What number would you like the information for? "))
- ... choice = input("Would you like to know "
- ... "1: If it's even/odd "
- ... "2: If it's prime/composite "
- ... "3: The square root "
- ... "4: The square of the number "
- ... "5: The factors of the number "
- ... "6: All of the above ")
- ... if choice == "1":
- ... even_tester(num)
- ... elif choice == "2":
- ... prime_tester(num)
- ... elif choice == "3":
- ... square_root_finder(num)
- ... elif choice == "4":
- ... x_squared(num)
- ... elif choice == "5":
- ... factor_finder(num)
- ... elif choice == "6":
- ... even_tester(num)
- ... prime_tester(num)
- ... square_root_finder(num)
- ... x_squared(num)
- ... factor_finder(num)
- ... else:
- ... print("That wasn't an option")
- ...
- >>> number_info()
- What number would you like the information for? >? 5
- Would you like to know 1: If it's even/odd 2: If it's prime/composite 3: The square root 4: The square of the number 5: The factors of the number 6: All of the above >? 5
- The factors of 5 are [1, 5]
- >>> def number_info():
- ... num = float(input("What number would you like the information for? "))
- ... choice = input("Would you like to know "
- ... "1: If it's even/odd "
- ... "2: If it's prime/composite "
- ... "3: The square root "
- ... "4: The square of the number "
- ... "5: The factors of the number "
- ... "6: All of the above ")
- ... choices = [
- ...
- ... ]
- ... for i in range(0, len(choice)):
- ... choices.append(choice[i])
- ... for i in range(0,len(choices)):
- ... if choices[i] == "1":
- ... even_tester(num)
- ... elif choices[i] == "2":
- ... prime_tester(num)
- ... elif choices[i] == "3":
- ... square_root_finder(num)
- ... elif choices[i] == "4":
- ... x_squared(num)
- ... elif choices[i] == "5":
- ... factor_finder(num)
- ... elif choices[i] == "6":
- ... even_tester(num)
- ... prime_tester(num)
- ... square_root_finder(num)
- ... x_squared(num)
- ... factor_finder(num)
- ... else:
- ... print("That wasn't an option")
- ...
- >>> number_info()
- What number would you like the information for? >? 5
- Would you like to know 1: If it's even/odd 2: If it's prime/composite 3: The square root 4: The square of the number 5: The factors of the number 6: All of the above >? 12
- 5.0 is odd
- 5.0 is prime
- >>> def number_info():
- ... factor_already = False
- ... squared_already = False
- ... root_already = False
- ... prime_already = False
- ... even_already = False
- ... num = float(input("What number would you like the information for? "))
- ... choice = input(
- ... "Would you like to know, if you wish to do multiple, put the numbers in a row as a big number ex. 1235 "
- ... "1: If it's even/odd "
- ... "2: If it's prime/composite "
- ... "3: The square root "
- ... "4: The square of the number "
- ... "5: The factors of the number "
- ... "6: All of the above ")
- ... choices = [
- ...
- ... ]
- ... for i in range(0, len(choice)):
- ... choices.append(choice[i])
- ... for i in range(0, len(choices)):
- ... if choices[i] == "1":
- ... if not even_already:
- ... even_tester(num)
- ... even_already = True
- ... elif choices[i] == "2":
- ... if not prime_already:
- ... prime_tester(num)
- ... prime_already = True
- ... elif choices[i] == "3":
- ... if not root_already:
- ... square_root_finder(num)
- ... root_already = True
- ... elif choices[i] == "4":
- ... if not squared_already:
- ... x_squared(num)
- ... squared_already = True
- ... elif choices[i] == "5":
- ... if not factor_already:
- ... factor_finder(num)
- ... factor_already = True
- ... elif choices[i] == "6":
- ... if not even_already:
- ... even_tester(num)
- ... even_already = True
- ... if not prime_already:
- ... prime_tester(num)
- ... prime_already = True
- ... if not root_already:
- ... square_root_finder(num)
- ... root_already = True
- ... if not squared_already:
- ... x_squared(num)
- ... squared_already = True
- ... if not factor_already:
- ... factor_finder(num)
- ... factor_already = True
- ... else:
- ... print("That wasn't an option")
- ...
- >>> number_info
- <function number_info at 0x0467A3D8>
- >>> 5
- 5
- >>> number_info()
- What number would you like the information for? >? 4
- Would you like to know, if you wish to do multiple, put the numbers in a row as a big number ex. 1235 1: If it's even/odd 2: If it's prime/composite 3: The square root 4: The square of the number 5: The factors of the number 6: All of the above >? 1325
- 4.0 is even
- The square root of 4.0 is 2.0
- 4.0 is composite
- The factors of 4 are [1, 2, 4]
- >>> def number_info():
- ... factor_already = False
- ... squared_already = False
- ... root_already = False
- ... prime_already = False
- ... even_already = False
- ... num = float(input("What number would you like the information for? "))
- ... print("1: If it's even/odd")
- ... print("2: If it's prime/composite")
- ... print("3: The square root")
- ... print("4: The square of the number")
- ... print("5: The factors of the number")
- ... print("6: All of the above")
- ... choice = input(
- ... "Would you like to know, if you wish to do multiple, put the numbers in a row as a big number ex. 1235 ")
- ... choices = [
- ... ]
- ... for i in range(0, len(choice)):
- ... choices.append(choice[i])
- ... for i in range(0, len(choices)):
- ... if choices[i] == "1":
- ... if not even_already:
- ... even_tester(num)
- ... even_already = True
- ... elif choices[i] == "2":
- ... if not prime_already:
- ... prime_tester(num)
- ... prime_already = True
- ... elif choices[i] == "3":
- ... if not root_already:
- ... square_root_finder(num)
- ... root_already = True
- ... elif choices[i] == "4":
- ... if not squared_already:
- ... x_squared(num)
- ... squared_already = True
- ... elif choices[i] == "5":
- ... if not factor_already:
- ... factor_finder(num)
- ... factor_already = True
- ... elif choices[i] == "6":
- ... if not even_already:
- ... even_tester(num)
- ... even_already = True
- ... if not prime_already:
- ... prime_tester(num)
- ... prime_already = True
- ... if not root_already:
- ... square_root_finder(num)
- ... root_already = True
- ... if not squared_already:
- ... x_squared(num)
- ... squared_already = True
- ... if not factor_already:
- ... factor_finder(num)
- ... factor_already = True
- ... else:
- ... print("That wasn't an option")
- ...
- >>> number_info()
- What number would you like the information for? >? 5
- 1: If it's even/odd
- 2: If it's prime/composite
- 3: The square root
- 4: The square of the number
- 5: The factors of the number
- 6: All of the above
- Would you like to know, if you wish to do multiple, put the numbers in a row as a big number ex. 1235 >? 134
- 5.0 is odd
- The square root of 5.0 is 2.23606797749979
- The square of 5.0 is 25.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement