0
我試圖運行此代碼,但它給了我以下錯誤:不能將int轉換成字符串
Traceback (most recent call last):
File "C:/Users/Admin/Desktop/gess.py", line 29, in <module>
print('arasworia, chemi chafiqrebuli cifri iyo ' + cif)
TypeError: Can't convert 'int' object to str implicitly
下面是代碼:
import random
guessTaken = 0
print(' ra gqvia? ')
sax = input()
cif = random.randint(1, 10)
print('Gamarjoba ' + sax + ' me vfiqrob cifrs, romelic aris 1 dan 10-mde! da gaqs 3 cda ')
while guessTaken < 3:
print(' chaifiqre cifri')
vard = input()
vard = int(vard)
guessTaken = guessTaken + 1
if vard < cif:
print(' Ufro dabal cifrs vfiqrob ')
if vard > cif:
print(' ufro magal cifrs vqirob ')
if vard == cif:
break
if vard == cif:
guessTaken = str(guessTaken)
print('gilocav ' + sax + 'shen gamoicane cifr ' + guessTaken + ' cdashi!')
if vard != cif:
cif == str(cif)
print('arasworia, chemi chafiqrebuli cifri iyo ' + cif)
爲什麼downvote?歡迎反饋。 – Christian
這應該是+1。比較運算符錯誤是解決方案。 – Will