TypeError: must be str, not int Python3 issue [duplicate]











up vote
-1
down vote

favorite













This question already has an answer here:




  • How can I concatenate str and int objects?

    3 answers




What's wrong with the line6:



 name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff)


I keep getting error:



TypeError: must be str, not int


How do you guys debug in general? I'm new to programming. Is there a way to know exactly where it wants string?










share|improve this question















marked as duplicate by jpp python-3.x
Users with the  python-3.x badge can single-handedly close python-3.x questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 5 at 19:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • You should be able to see the line number where the error occurred in the traceback. In general, you can debug by removing things until the error disappears, then put the last thing you removed back (in which you will find the error).
    – L3viathan
    Nov 5 at 18:18















up vote
-1
down vote

favorite













This question already has an answer here:




  • How can I concatenate str and int objects?

    3 answers




What's wrong with the line6:



 name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff)


I keep getting error:



TypeError: must be str, not int


How do you guys debug in general? I'm new to programming. Is there a way to know exactly where it wants string?










share|improve this question















marked as duplicate by jpp python-3.x
Users with the  python-3.x badge can single-handedly close python-3.x questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 5 at 19:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • You should be able to see the line number where the error occurred in the traceback. In general, you can debug by removing things until the error disappears, then put the last thing you removed back (in which you will find the error).
    – L3viathan
    Nov 5 at 18:18













up vote
-1
down vote

favorite









up vote
-1
down vote

favorite












This question already has an answer here:




  • How can I concatenate str and int objects?

    3 answers




What's wrong with the line6:



 name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff)


I keep getting error:



TypeError: must be str, not int


How do you guys debug in general? I'm new to programming. Is there a way to know exactly where it wants string?










share|improve this question
















This question already has an answer here:




  • How can I concatenate str and int objects?

    3 answers




What's wrong with the line6:



 name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff)


I keep getting error:



TypeError: must be str, not int


How do you guys debug in general? I'm new to programming. Is there a way to know exactly where it wants string?





This question already has an answer here:




  • How can I concatenate str and int objects?

    3 answers








python python-3.x debugging






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 5 at 17:07









khelwood

29.1k63960




29.1k63960










asked Nov 5 at 17:00









Galapagos

12715




12715




marked as duplicate by jpp python-3.x
Users with the  python-3.x badge can single-handedly close python-3.x questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 5 at 19:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by jpp python-3.x
Users with the  python-3.x badge can single-handedly close python-3.x questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 5 at 19:46


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • You should be able to see the line number where the error occurred in the traceback. In general, you can debug by removing things until the error disappears, then put the last thing you removed back (in which you will find the error).
    – L3viathan
    Nov 5 at 18:18


















  • You should be able to see the line number where the error occurred in the traceback. In general, you can debug by removing things until the error disappears, then put the last thing you removed back (in which you will find the error).
    – L3viathan
    Nov 5 at 18:18
















You should be able to see the line number where the error occurred in the traceback. In general, you can debug by removing things until the error disappears, then put the last thing you removed back (in which you will find the error).
– L3viathan
Nov 5 at 18:18




You should be able to see the line number where the error occurred in the traceback. In general, you can debug by removing things until the error disappears, then put the last thing you removed back (in which you will find the error).
– L3viathan
Nov 5 at 18:18












2 Answers
2






active

oldest

votes

















up vote
1
down vote













Python can't automatically convert integer variable to string.



You need to explicitly convert future variable to str type like this:



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)





share|improve this answer





















  • this worked thanks
    – Galapagos
    Nov 5 at 19:39


















up vote
0
down vote













future is an integer, therefore, it cannot be concatenated with a string. You can do this:



print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


OR cast int to str



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


Output:



C:UsersDocuments>py test.py
Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023 you will turn 147


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Output:



Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023you will turn 147





share|improve this answer























  • your solution doesn't seem to work:
    – Galapagos
    Nov 5 at 19:38










  • Why? It is working
    – Rarblack
    Nov 5 at 19:41










  • Look both are perfectly working @Galapagos.
    – Rarblack
    Nov 5 at 19:45










  • the original suggested: future = str(int(today + 5)) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) so inserting into the code: name = (input('Hi, please enter your name ')) dob = int(input('Hi please enter your DOB ')) today = int(input("Hi please enter today's date ")) future = str(int(today + 5)) diff = str(future - dob) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) does not work .
    – Galapagos
    Nov 5 at 19:45












  • I know what is your point?
    – Rarblack
    Nov 5 at 19:46


















2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Python can't automatically convert integer variable to string.



You need to explicitly convert future variable to str type like this:



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)





share|improve this answer





















  • this worked thanks
    – Galapagos
    Nov 5 at 19:39















up vote
1
down vote













Python can't automatically convert integer variable to string.



You need to explicitly convert future variable to str type like this:



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)





share|improve this answer





















  • this worked thanks
    – Galapagos
    Nov 5 at 19:39













up vote
1
down vote










up vote
1
down vote









Python can't automatically convert integer variable to string.



You need to explicitly convert future variable to str type like this:



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)





share|improve this answer












Python can't automatically convert integer variable to string.



You need to explicitly convert future variable to str type like this:



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 5 at 17:04









Dmitriy Fialkovskiy

1,4821224




1,4821224












  • this worked thanks
    – Galapagos
    Nov 5 at 19:39


















  • this worked thanks
    – Galapagos
    Nov 5 at 19:39
















this worked thanks
– Galapagos
Nov 5 at 19:39




this worked thanks
– Galapagos
Nov 5 at 19:39












up vote
0
down vote













future is an integer, therefore, it cannot be concatenated with a string. You can do this:



print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


OR cast int to str



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


Output:



C:UsersDocuments>py test.py
Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023 you will turn 147


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Output:



Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023you will turn 147





share|improve this answer























  • your solution doesn't seem to work:
    – Galapagos
    Nov 5 at 19:38










  • Why? It is working
    – Rarblack
    Nov 5 at 19:41










  • Look both are perfectly working @Galapagos.
    – Rarblack
    Nov 5 at 19:45










  • the original suggested: future = str(int(today + 5)) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) so inserting into the code: name = (input('Hi, please enter your name ')) dob = int(input('Hi please enter your DOB ')) today = int(input("Hi please enter today's date ")) future = str(int(today + 5)) diff = str(future - dob) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) does not work .
    – Galapagos
    Nov 5 at 19:45












  • I know what is your point?
    – Rarblack
    Nov 5 at 19:46















up vote
0
down vote













future is an integer, therefore, it cannot be concatenated with a string. You can do this:



print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


OR cast int to str



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


Output:



C:UsersDocuments>py test.py
Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023 you will turn 147


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Output:



Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023you will turn 147





share|improve this answer























  • your solution doesn't seem to work:
    – Galapagos
    Nov 5 at 19:38










  • Why? It is working
    – Rarblack
    Nov 5 at 19:41










  • Look both are perfectly working @Galapagos.
    – Rarblack
    Nov 5 at 19:45










  • the original suggested: future = str(int(today + 5)) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) so inserting into the code: name = (input('Hi, please enter your name ')) dob = int(input('Hi please enter your DOB ')) today = int(input("Hi please enter today's date ")) future = str(int(today + 5)) diff = str(future - dob) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) does not work .
    – Galapagos
    Nov 5 at 19:45












  • I know what is your point?
    – Rarblack
    Nov 5 at 19:46













up vote
0
down vote










up vote
0
down vote









future is an integer, therefore, it cannot be concatenated with a string. You can do this:



print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


OR cast int to str



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


Output:



C:UsersDocuments>py test.py
Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023 you will turn 147


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Output:



Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023you will turn 147





share|improve this answer














future is an integer, therefore, it cannot be concatenated with a string. You can do this:



print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


OR cast int to str



print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ', future, 'you will turn ' + diff)


Output:



C:UsersDocuments>py test.py
Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023 you will turn 147


Example:



name = (input('Hi, please enter your name '))
dob = int(input('Hi please enter your DOB '))
today = int(input("Hi please enter today's date "))
future = int(today + 5)
diff = str(future - dob)
print ('Hi ' + name + 'in the year of ' + str(future) + 'you will turn ' + diff)


Output:



Hi, please enter your name job
Hi please enter your DOB 1876
Hi please enter today's date 2018
Hi jobin the year of 2023you will turn 147






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 5 at 19:51

























answered Nov 5 at 17:30









Rarblack

1




1












  • your solution doesn't seem to work:
    – Galapagos
    Nov 5 at 19:38










  • Why? It is working
    – Rarblack
    Nov 5 at 19:41










  • Look both are perfectly working @Galapagos.
    – Rarblack
    Nov 5 at 19:45










  • the original suggested: future = str(int(today + 5)) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) so inserting into the code: name = (input('Hi, please enter your name ')) dob = int(input('Hi please enter your DOB ')) today = int(input("Hi please enter today's date ")) future = str(int(today + 5)) diff = str(future - dob) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) does not work .
    – Galapagos
    Nov 5 at 19:45












  • I know what is your point?
    – Rarblack
    Nov 5 at 19:46


















  • your solution doesn't seem to work:
    – Galapagos
    Nov 5 at 19:38










  • Why? It is working
    – Rarblack
    Nov 5 at 19:41










  • Look both are perfectly working @Galapagos.
    – Rarblack
    Nov 5 at 19:45










  • the original suggested: future = str(int(today + 5)) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) so inserting into the code: name = (input('Hi, please enter your name ')) dob = int(input('Hi please enter your DOB ')) today = int(input("Hi please enter today's date ")) future = str(int(today + 5)) diff = str(future - dob) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) does not work .
    – Galapagos
    Nov 5 at 19:45












  • I know what is your point?
    – Rarblack
    Nov 5 at 19:46
















your solution doesn't seem to work:
– Galapagos
Nov 5 at 19:38




your solution doesn't seem to work:
– Galapagos
Nov 5 at 19:38












Why? It is working
– Rarblack
Nov 5 at 19:41




Why? It is working
– Rarblack
Nov 5 at 19:41












Look both are perfectly working @Galapagos.
– Rarblack
Nov 5 at 19:45




Look both are perfectly working @Galapagos.
– Rarblack
Nov 5 at 19:45












the original suggested: future = str(int(today + 5)) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) so inserting into the code: name = (input('Hi, please enter your name ')) dob = int(input('Hi please enter your DOB ')) today = int(input("Hi please enter today's date ")) future = str(int(today + 5)) diff = str(future - dob) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) does not work .
– Galapagos
Nov 5 at 19:45






the original suggested: future = str(int(today + 5)) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) so inserting into the code: name = (input('Hi, please enter your name ')) dob = int(input('Hi please enter your DOB ')) today = int(input("Hi please enter today's date ")) future = str(int(today + 5)) diff = str(future - dob) print ('Hi ' + name + 'in the year of ' + future + 'you will turn ' + diff) does not work .
– Galapagos
Nov 5 at 19:45














I know what is your point?
– Rarblack
Nov 5 at 19:46




I know what is your point?
– Rarblack
Nov 5 at 19:46



這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()