5

right sorry that I'm not all good at python but my problem is that i need to replace a character
here is the thing i am trying to change all i need to change is # to an A for all of the lines

def puzzle():
print ("#+/084&;")
print ("#3*#%#+")
print ("8%203:")
print (",1$&")
print ("!-*%")
print (".#7&33&")
print ("#*#71%")
print ("&-&641'2")
print ("#))85")
print ("9&330*;")

so here is what i attempted to do(it was in another py file)

from original_puzzle import puzzle

puzzle()

result = puzzle()

question = input("first letter ")

for letter in question:
    if letter == "a":
        result = result.replace("#","A")
        print (result)

here is what it gives me

 Traceback (most recent call last):
  File "N:\AQA 4512;1-practical programming\code\game.py", line 36, in <module>
    result = result.replace("#","A")
AttributeError: 'NoneType' object has no attribute 'replace'

it would help if somebody told me a different way around it aswell thanks for the help and sorry again that i'm bad at python

2
  • Have a look at what puzzle() returns. Commented Jun 13, 2014 at 11:01
  • See also stackoverflow.com/questions/21471876/… Commented Jun 13, 2014 at 11:07

2 Answers 2

4

if you don't explicitly return something from a python function, python returns None.

>>> def puzzle():
...   print 'hi'
... 
>>>
>>> puzzle() is None
hi
True
>>> def puzzle():
...   print 'hi'
...   return None
... 
>>> puzzle() is None
hi
True
>>> def puzzle():
...   return 'hi'
... 
>>> puzzle()        
'hi'
>>> puzzle() is None
False
>>> 
Sign up to request clarification or add additional context in comments.

Comments

0

The puzzle() function does not return anything. That's why you get this error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.