def getPentagonalNumber(i):
pentNumber = (((i) * ((3 * i) - 1)) // 2)
print(str("pentagonalNumber"),end = " ")
def main():
for i in range(1,101):
getPentagonalNumber(i)
if i % 10 != 0:
print(format(getPentagonalNumber(i), "6d"),end = "")
else:
return()
main()
getPentagonalNumber(value)
print(str("pentagonalNumber"), end=" ")
def getPentagonalNumber(i):
pentagonalNumber = (((i) * ((3 * i) - 1)) // 2)
print(str(pentagonalNumber), end = " ")
for i in range (1,101):
getPentagonalNumber(i)
if i % 10 != 0:
print()
def getPentagonalNumber(i):
pentagonalNumber = (((i) * ((3 * i) - 1)) // 2)
for i in range (1,101):
getPentagonalNumber(i)
if i % 10 != 0:
print(format(getPentagonalNumber(i), "6d"))
else:
print(format(getPentagonalNumber(i), "6d"), end = " ")
return pentagonalNumber
return pentagonalNumber
^
SyntaxError: 'return' outside function
def getPentagonalNumber(i):
return (((i) * ((3 * i) - 1)) // 2) # this is the part i keep saying needs
# to return the value
for i in range(1, 101):
pentNum = getPentagonalNumber(i) # get the return value here
if i % 10 != 0:
print(format(pentNum, "6d")) # use the returned value here
else:
print(format(pentNum, "6d"), end=" ") # use the returned value here
def isPrime(number):
divisor = 2
while divisor <= number / 2:
if number % divisor == 0:
return False # number is not a prime
divisor += 1
return True # number is prime
for i in range (1, 1001):
if isPrime(number):
value = number + 1
print("(",number,",", value,")", end = ")
if count % NUMBER_OF_PRIMES_PER_LINE == 0:
print()
number += 1
def main():
for i in range(1000):
if isPrime(i):
if isPrime(i + 2):
print('(' + str(i) + ',',str(i + 2) + ')', end = ")
print()
main()
False # number is not a prime
^
TabError: inconsistent use of tabs and spaces in indentation
Incorrect result!
ef isPrime(number):
divisor = 2
while divisor <= number / 2:
if number % divisor == 0:
return False # number is not a prime
divisor += 1
return True # number is a prime
def printTwinPrimeNumbers(twinPrime):
NUMBER_OF_PRIMES = 50
NUMBER_OF_PRIMES_PER_LINE = 10
number = 1 # number to be tested for primess
count = 0
for i in range(1, 1001):
if isPrime(number):
value = number + 1
print("(", number,",", value,")", end = '')
if count % NUMBER_OF_PRIMES_PER_LINE == 0:
print()
number += 1
def main():
print("The first 50 twin prime numbers are: ")
printTwinPrimeNumbers(50)
main()
i get an error on line 24 stating that 'number' is not defined
def isPrime(number):
divisor = 2
while divisor <= number / 2:
if number % divisor == 0:
return False # number is not a prime
divisor += 1
return True # number is prime
for i in range (1, 1001):
if isPrime(number):
value = number + 1
print("(",number,",", value,")", end = "")
if count % NUMBER_OF_PRIMES_PER_LINE == 0:
print()
number += 1
def main():
for i in range(1000):
if isPrime(i):
if isPrime(i + 2):
print('(' + str(i) + ',',str(i + 2) + ')', end = ")
print()
main()
if isPrime(i + 2):
^
TabError: inconsistent use of tabs and spaces in indentation
def main():
for i in range(1000):
if isPrime(i):
if isPrime(i + 2):
print('(' + str(i) + ',',str(i + 2) + ')', end = ")
print()
if isPrime(i + 2):
^
TabError: inconsistent use of tabs and spaces in indentation
if isPrime(i + 2):
def number():
number = 1
def isPrime(number):
def number():
divisor = 2
while divisor <= number / 2:
if number % divisor == 0:
return False # number is not a prime
divisor += 1
return True # number is prime
for i in range (1, 1001):
if isPrime(number):
value = number + 1
print("(",number,",", value,")", end = "")
if count % NUMBER_OF_PRIMES_PER_LINE == 0:
print()
number += 1
def main():
for i in range(1000):
if isPrime(i):
if isPrime(i + 2):
print('(' + str(i) + ',',str(i + 2) + ')', end = "")
print()
main()
return False # number is not a prime
^
IndentationError: expected an indented block
if number % divisor == 0:
def isPrime(number):
divisor = 2
while divisor <= number / 2:
if number % divisor == 0:
return False # number is not a prime
divisor += 1
return True # number is prime
def printTwinPrimeNumbers(twinPrime):
NUMBER_OF_PRIMES = 50
number = 2 # number to be tested for primeness
for i in range(1, 1001):
if isPrime(number):
value = number + 2
print("(", number, ",", value, ")", end = '')
number += 1
def main():
print("The Twin Prime Numbers are: ")
printTwinPrimeNumbers(50)
main()
Users browsing this forum: No registered users and 10 guests