Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
x = int(input())

a = 12
sestdiena = x//a
sestdienaa = x%a
print(sestdiena, str(sestdienaa) + "/" + str(a))
print("Sestdien piepildīja" + sestdiena + "kastītes, nepilnajā kastītē bija" + sestdienaa + " olas .")



Traceback (most recent call last):
File "jdoodle.py", line 7, in <module>
print("Sestdien piepildīja" + sestdiena + "kastītes, nepilnajā kastītē bija" + sestdienaa + " olas .")
TypeError: can only concatenate str (not "int") to str

What I have tried:

How can that error be solved?? And again- explain and/or show/write as simple as you can because I'm stupid in programming. Thank you guys, I really appreciate it.
Posted
Updated 13-Nov-20 22:56pm

Hi,
This is just a hint ...
Your first print line is OK, but there is a problem on the second print line.
It has to do with concatenating string and int types as the compiler says ...
Can you spot it now ?
Good luck
Regards
 
Share this answer
 
Comments
Helmuts Helmuts 13-Nov-20 16:23pm    
Well I can't spot it now either. Problem is that I don't understand what concatening string and int types mean.
peterkmx 14-Nov-20 4:33am    
Hi, Concatenating refers to using + operator to "attach" string variables such as s = s1 + s2. Another hint is that Python has implicit typing of variables. When creating a variable, Python compiler understands its type automatically and remembers that. We humans cannot see this immediately in the code and have to remember this. Variables such as
a = 2
b = "xyz"
have different types, in this case integer and string ...
Does this help to see the problem ?
Helmuts Helmuts 14-Nov-20 8:12am    
So. You want to say, that I have to convert that "sestdiena", which is only one in that print line which is not str, to str??

Edit. I did it, but now it shows another error.
that line now looks this
print(str(sestdiena), str(sestdienaa) + "/" + str(a))
And error shown is this
File "jdoodle.py", line 5, in <module>
print(str(sestdiena), str(sestdienaa) + "/" + str(a))
TypeError: 'int' object is not callable.

how to fix that??
peterkmx 14-Nov-20 15:40pm    
Hi,
Using Python 3 in a Jupyter Notebook I modified your code as follows

x = 7
a = 12
sestdiena = x//a
sestdienaa = x%a
print(sestdiena, str(sestdienaa) + "/" + str(a))
print("Sestdien piepildīja" + str(sestdiena) + "kastītes, nepilnajā kastītē bija" + str(sestdienaa) + " olas .")

and in this case the result is:

0 7/12
Sestdien piepildīja0kastītes, nepilnajā kastītē bija7 olas .

There is no error ...

To practice Python, I suggest that you install Anaconda and use Jupyter Notebooks as it is an interactive environment, or use an online Python snippet tool such as this one

https://paiza.io/projects/l6x0MkNrSGtCjY46G_QZnA?language=python3

Both environments are really helpful when learning Python
Hope that this helps ...
Cheers
Helmuts Helmuts 15-Nov-20 4:30am    
It really worked. Thank you very very much! :)))
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

We certainly aren't here to get you through a "programming test" and into a job you can't do:
Quote:
I'm quite stupid at pgoramming
Other candidates (who can do the job) deserve the interview more than you do ...

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 
You cannot concatenated variables by adding numbers to strings. You must convert any numbers to strings first, as you have done in the first print statement.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900