user3267164
user3267164

Reputation: 11

Can't convert int to string

I'm trying to run this code but it gives me following error:

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

Here is the code:

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)

Upvotes: 0

Views: 95

Answers (2)

Christian Tapia
Christian Tapia

Reputation: 34176

You can use str() inside the print function:

print('arasworia, chemi chafiqrebuli cifri iyo ' + str(cif))

Also, note that == is used to check equality. Use = for assignment. Use

cif = str(cif)

instead of

cif == str(cif)

Upvotes: 1

NPE
NPE

Reputation: 500853

The

cif == str(cif)

should be

cif = str(cif)

In Python, == is comparison and = is assignment.

Upvotes: 2

Related Questions