Diğer soruları okuyorum ama yapmaya çalıştığım şey farklı bir python'unda bir hesap makinesi şeyleri yapmaya çalışıyorum ve değişken girdi nesnesini bir tamsayı böylece ekleyebilirim. Bu benim kodu da onun henüz bitmediğini ve bir acemi im değil:TypeError: 'int' nesnesini str dolaylı olarak hata pythonuna dönüştüremiyorum
print("Hello! Whats your name?")
myName = input()
print("What do you want me to do? " + myName)
print("I can add, subtract, multiply and divide.")
option = input('I want you to ')
if option == 'add':
print('Enter a number.')
firstNumber = input()
firstNumber = int(firstNumber)
print('Enter another number.')
secondNumber = input()
secondNumber = int(secondNumber)
answer = firstNumber + secondNumber
print('The answer is ' + answer)
ne yaptığını:
Hello! Whats your name?
Jason
What do you want me to do? Jason
I can add, subtract, multiply and divide.
I want you to add
Enter a number.
1
Enter another number.
1
Traceback (most recent call last):
File "C:/Python33/calculator.py", line 17, in <module>
print('The answer is ' + answer)
TypeError: Can't convert 'int' object to str implicitly
herhangi bir yardım mutluluk duyacağız :)
hata mesajı olarak
' print' işlevi, herhangi bir dize olmayan argümanları otomatik olarak "str" ile dönüştürecektir. – Blckknght
Sanırım bana yardım ettiniz :) Ben baskı yapmam gerekiyordu ('Cevap {}'. Biçim (cevap))? – soupuhman
@soupuhman, Evet, 'print (' cevap {} '. Format (cevap)) 'veya' print (' cevaptır ', cevapla) 'Blckknght'ın yorumladığı gibi yapabilirsiniz. – falsetru