0

UPDATED CODE , got it working but im repeating lines above and below my while loop. any friendly advice to solve this error, just looking for some guidance .

import pyperclip
import random

x=random.randint(1,10)

pyperclip.copy(x)
print(str(int(pyperclip.paste())))





     
def guessingGame(answer):
    if(casting==x):
        print("correct")
        return True
    elif(casting<x):
        print("higher")
        return False
    else:
        print("lower")
        return False
    


userAnswer=input()
casting=int(userAnswer)
guessingGame(casting)
while(guessingGame!=True):
    userAnswer=input()
    casting=int(userAnswer)
    guessingGame(casting)

I am trying to create a simple guessing game, and am running into an AttributeError. Here is an input that causes the error:

lets play a guessing game, can you get our number? type in your guess
2

Traceback (most recent call last):
File "E:/guessing.py", line 25, in <module>
    while(guess(userAnswer)==False):
File "E:/guessing.py", line 9, in guess
    print(str(int(copying.paste()))+" higher")
AttributeError: 'NoneType' object has no attribute 'paste'

Here is my code:

import pyperclip
import random

x=random.randint(1,10)

def guess(value):
    copying=pyperclip.copy(int(value))
    if(value<x):
        print(str(int(copying.paste()))+" higher")
        return False
    elif(value>x):
        copying=pyperclip.copy(value)
        print(str(int(copying.paste()))+" lower")
        return False
    else:
        printcopying=pyperclip.copy(value)
        print(str(int(copying.paste()))+" correct guess our number was "+ str(int(value)))
        return True


print("lets play a guessing game, can you get our number? type in your guess")
userAnswer=int(input())


while(guess(userAnswer)==False):
    print("lets play a guessing game, can you get our number? type in your guess")
    userAnswer
    guess(userAnswer)
RocStream
  • 67
  • 7
  • Woahs, that was some very strange syntax highlighting for a second there. – Mateen Ulhaq Jun 12 '18 at 01:34
  • 3
    The error is not *Traceback*. That's a stack trace. The error is * AttributeError: 'NoneType' object has no attribute 'paste'*, which you can find information about by searching here for *nonetype object has no attribute*. – Ken White Jun 12 '18 at 01:35
  • 1
    Please use a title that describes the specific problem you're having. – Barmar Jun 12 '18 at 01:35
  • Why are you using the pyperclip library for this? – whackamadoodle3000 Jun 12 '18 at 01:36
  • just a new skill I learned and wanted to combine a bit of everything – RocStream Jun 12 '18 at 01:38
  • This error occurs when you try to access an attribute (e.g., the `.paste` method) of a variable that is actually set to have the value of `None`. `None` doesn't have any attributes, so this is an error. You should look earlier to see why your variable got a value of `None` instead of being some object with attributes. Sometimes functions return `None` when there is an error, but functions also return `None` if they have no explicit return statement (i.e. aren't really meant to return anything). Did something go wrong with `pyperclip.copy`? Is it normally meant to return something? – Matthias Fripp Jun 12 '18 at 01:41
  • I'm guessing that you may need to use `pyperclip.paste()` instead of `copying.paste()` (assuming pyperclip is some tool for copying things on and off the system clipboard). – Matthias Fripp Jun 12 '18 at 01:44
  • Yes its meant to access the rams memory , it utilizes the clipboard – RocStream Jun 12 '18 at 01:58
  • I got it working but still seems unsatisfactory with multiple lines of the same code – RocStream Jun 12 '18 at 01:59

0 Answers0