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)