Thread has been deleted
Last comment
simple weight convert: Code: weight_lbs = input('Weight (lbs): ') weight_kg = int(weight_lbs) * 0.45 print('Weight (kg): ' + weight_kg) i got an error Traceback (most recent call last): File "C:/Users/xxx/PycharmProjects/Helllo World/app.py", line 3, in <module> print('Weight (kg): ' + weight_kg) TypeError: can only concatenate str (not "float") to str why is that?
2019-10-21 01:22
Topics are hidden when running Sport mode.
#1
 | 
Netherlands n0b8m8 
Nerd alert 0/8
2019-10-21 01:23
i have hight iq and it's not my fault i was born this way
2019-10-21 01:24
#6
koosta | 
United States yghj 
u are writing a weight conversion python program. not very high level coding
2019-10-21 01:26
dude i started an hour ago
2019-10-21 01:26
#12
koosta | 
United States yghj 
ok mens, doesnt make you smart. you are having trouble with this right here. by multiplying by .45 you made the variable a float. because of this it is havingtrouble printing it because it wants to print a string not a float. (a decimal number). that is what the error means.
2019-10-21 01:28
nah i'm very smart just confused with life purpse, making money and girls but other than that im top1
2019-10-21 02:13
smart people never boast about being smart, trust me.
2019-10-21 08:15
#60
 | 
Europe Kilian_9047 
+1
2019-10-21 08:33
i can do whatever I want in fact, i am so smart that I don't have any need for approval of your codexs of morality or ethics
2019-10-21 20:37
lmao ur so infatuated and delusional u made a thread about python which is like the easiest coding language to learn asking for help and then u say you don’t care about other people helping you? This is next gen stupidity dude
2019-10-22 15:00
no idea idea what are you talking about, it seems like you have some problems with comprehension reading, and project your own insecurities onto me yes I wanted help in a programing, so what? but then you tell me how I should act and behave - because you think it's right and I said Fuck you. Turn on logic
2019-10-22 15:13
how old are you?
2019-10-22 15:03
old enough, none of your business
2019-10-22 15:06
so ur basically like 20 something, dont have a job nor a girl and u say ur top1? Ur delusional asf also never told u how to behave or how to act. Go learn python, get a job, and stop wasting your time on hltv, also this is an advice.
2019-10-22 15:18
who are you to give me advice and tellming how to live? Mr. Ion Popescu I don't need nor I want your advices - GTFO it's my life
2019-10-22 15:27
yeah aight
2019-10-22 16:48
replace, with .
2019-10-21 01:24
#5
 | 
Germany MackyGee 
there are no commas in his code
2019-10-21 01:25
#8
koosta | 
United States yghj 
maybe he means replace the . in 0.45 with , because europe
2019-10-21 01:26
#11
 | 
Germany MackyGee 
but he said , with . 🤔🤔
2019-10-21 01:27
#14
koosta | 
United States yghj 
idk mens just trying t help
2019-10-21 01:28
#4
koosta | 
United States yghj 
python? maybe it is because of the casting. why would you cast weight_lbs to int if you multiply by a double in the same line?
2019-10-21 01:25
yes python but i don't don't understand what you wrote what is casting
2019-10-21 01:27
#17
koosta | 
United States yghj 
casting is when you make a variable type into a nother variable type. so if i cast 1.5 oi would do double double_var = 1.5; int int_var = (int) 1.5; println(int_var); "1" i took a double and made it into an int, and it rounded it down to the nearest integer 1. a float is kidna like double but it has a larger capacity for bits. so a double could be 1.24 and a float would be better like this = 1.243483792012383948 what is going on in your code is it thinks that the variable yo ugave was a string, aka letters and words, but yo uwant it to be an int. so you cast it by putting (int) in front.
2019-10-21 01:32
#9
 | 
Slovakia itsab8 
I havent touched python in ages but this edit should fix it weight_lbs = int(input('Weight (lbs): ')) print str(('Weight (kg): ' + weight_kg)) only input integers and not floats
2019-10-21 01:29
nope an error
2019-10-21 01:31
#23
koosta | 
United States yghj 
i replied to one of your comments about why
2019-10-21 01:35
#19
koosta | 
United States yghj 
+1 its just a casting problem where it dosnt wanna print floats or something
2019-10-21 01:31
#13
 | 
Germany chillhase 
And this code converts the weight of s1mple?
2019-10-21 01:28
yes give just give his lbs mens
2019-10-21 01:29
So you basically try to convert s1mple weights and make all of navi members fit and healty? what a noiceguy
2019-10-21 01:48
if I could do this that would make me the richest man in hltv ever
2019-10-21 02:10
#16
 | 
Bulgaria slaughtersun 
weight_lbs = int(input('Weight (lbs): ') ) This should work. Whenever u input sth, python thinks its a string and u need to make it an int,float or whatev
2019-10-21 01:30
#20
koosta | 
United States yghj 
+(int)"1"
2019-10-21 01:33
error print (('Weight (kg): ' + weight_kg)) TypeError: can only concatenate str (not "float") to st
2019-10-21 01:33
#22
koosta | 
United States yghj 
so it is problem with the print line. concatenate means to print after it. that is the plus sign you put htere. for somereason it thinkst hat the weight is a floar. try putting (int) in front of the variable name in the print(). its because you multiplied by .45 without casting. it became a float. if you want decimals then you should make it a (double)
2019-10-21 01:36
#24
 | 
Bulgaria slaughtersun 
weight_lbs = int(input('Weight (lbs): ')) weight_kg =weight_lbs * 0.45 print('Weight (kg): ', weight_kg) this should work you get this error because you're trying to concatenate a string and a nonstring (weight_kg is not a string)
2019-10-21 01:38
hah it doesn't weight_kg =weight_lbs * 0.45 TypeError: can't multiply sequence by non-int of type 'float' weight_lbs = input('Weight (lbs): ') weight_kg = int(weight_lbs) * 0.45 print('Weight (kg): ', weight_kg) this work why , instead of +? retarded
2019-10-21 01:41
#35
 | 
Bulgaria slaughtersun 
u can use + if u convert the weight_kg to a string but that seems a bit pointless to me
2019-10-21 01:46
weight_lbs = input('Weight (lbs): ') weight_kg = int(weight_lbs) * 0.45 print('Weight (kg): ' + str(weight_kg)) yeah this works as well
2019-10-21 02:11
#29
 | 
Australia Chereska 
This is still wrong Weight_lbs = int(input('Weight (lbs): ') Weight_kg = Weight_lbs * 0.45 Print ('Weight (kg):' , str(Weight_kg)) That should end up working
2019-10-21 01:47
#31
 | 
Bulgaria slaughtersun 
imgur.com/a/EKT4T5l seems to be working bro
2019-10-21 01:43
#39
 | 
Australia Chereska 
Am I missing something? Does "," change it to a str value?
2019-10-21 01:49
#41
 | 
Bulgaria slaughtersun 
it doesnt, you can put multiple arguments in a print() as far as i know and you just put a , between them
2019-10-21 01:51
#43
 | 
Australia Chereska 
Right, I've always used "+" because I like it more but I didn't know that you don't need the str if your using a ,
2019-10-21 01:54
#25
 | 
Australia Chereska 
You just need to str(weight_kg) in the final line instead of just weight_kg alone
2019-10-21 01:37
+1
2019-10-21 01:43
#40
 | 
Australia Chereska 
It worked?
2019-10-21 01:50
yes it does
2019-10-21 02:08
#32
 | 
Portugal Turambar 
I'm going with this. I mean the error is quite clear, can't figure how it was troubling to understand what it said.
2019-10-21 01:44
last line to print('Weight (kg): ' + str(weight_kg))
2019-10-21 01:38
+1 #25 & 26 true coders
2019-10-21 01:44
print('Weight (kg): ' + str(weight_kg))
2019-10-21 01:39
main(){ int wheightPounds(0); std::cin >> wheightPounds; std::cout << wheightPounds*0.45 << " KG.\n"; return(0); } IDK python but the problem seems to be that youre adding a string('Weight (kg): ') which is a literal to a float variable. Try and cast that float to a strig before u do that
2019-10-21 01:44
Or yet just print them separately
2019-10-21 01:46
#38
 | 
Bulgaria slaughtersun 
+1
2019-10-21 01:49
any BBA gang?
2019-10-21 01:51
idk idc
2019-10-21 02:11
#49
 | 
United States LoneTC 
Java >>>>>>>>>>>>>>>>>>>>> Python Change my mind
2019-10-21 03:43
#51
 | 
Finland D_Scimmy 
colab.research.google.com See for yourself
2019-10-21 04:04
Basic error. You can't concatenate that because you're setting (weight_kg) to an integer in line 2, then trying to add the integer to text in line 3. You can't just add integers to text because they are different data types, so instead if we just convert the number to string then we'll be fine: weight_lbs = input('Weight (lbs): ') weight_kg = int(weight_lbs) * 0.45 print('Weight (kg): ' + str(weight_kg))
2019-10-21 04:03
#52
 | 
Brazil Smartzilian 
str(weight_kg) convert using str() before concatenate w/ string
2019-10-21 04:16
this is your typical python "programmer" they dont know shit about typecasting let alone data types - CHECK has absolutely no knowledge about strings - CHECK jumps into writing codes without a grasp of the fundamentals of how I/Os work - CHECK another day to laugh at python indian programmers
2019-10-21 07:28
yes and this is the guy who wants to make money as a programmer next year. clowns next day you see him, failing on "hello world".
2019-10-21 07:32
"goodbye world"))))
2019-10-21 07:55
#59
 | 
Macedonia Zano0o 
shut up everyone has been a beginner once let him learn things on his own pace, don't judge languages, every language has its benefits for different purposes.
2019-10-21 08:32
"dont judge languages" things a boomer would say
2019-10-21 09:08
You should put , not + edit: what u are trying to do is printing string + int (error) and u can only do string + string so im assuming youre not trying to add those 2, you want to print weight_kg separately
2019-10-21 07:59
#58
 | 
United States fatburger 
im not a coder
2019-10-21 08:21
#61
 | 
United States gtmaniacmda 
weight_kg is an int type, not a string type, so the '+' can't be used that way (at least I assume so, you can't in C++ at least. I think in Java you can...) the string and the int should be printed separately, that would be the easiest way IMO or you can just fucking google it, I found the answer immediately...
2019-10-21 08:40
#62
 | 
United Kingdom Lcheste3 
On the last line you probably need to: print(‘Weight:’ + str(weight_kg))
2019-10-21 08:49
#64
 | 
United Kingdom Lcheste3 
Or maybe a comma instead of a plus might also work.
2019-10-21 08:49
#69
ropz | 
Czech Republic y0fl0w 
yes it would
2019-10-22 15:04
#73
 | 
India letgoboi 
+ for str , for others
2019-10-22 15:10
#63
 | 
Ukraine d1pal 
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int weight_lbs = Convert.ToInt32(Console.ReadLine()); double weight_kg = weight_lbs * 0.45; Console.WriteLine("Weight(kg):{0}",weight_kg); } } }
2019-10-21 08:49
i am way too smart comparing to u i started 30 min ago with java import java.io.*; import java.util.*; class PoundsTokg{ public static void main (String[] args)throws Exception{ //1 Pounds = 0.45 Kg; BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the Pounds:"); int pound = Integer.parseInt(bf.readLine()); double kilo = pound * 0.45; System.out.println("Kilo: " + kilo); } } enjoy my less smarter friend .
2019-10-22 15:09
#72
 | 
India letgoboi 
weight_lbs = float(input('Weight (lbs): ')) weight_kg = float(weight_lbs * 0.45) print('Weight (kg): ', weight_kg) say thanks
2019-10-22 15:10
You concatenate string with int in print function (+ is an operator for concatenating strings). You have to see the int as a string - convert the int to string. If print function support %d %s format types, then you can write print("weight: %d", weightValue), with weightValue as an int. I dont know if python has that.
2019-10-22 15:18
print('Weight (kg): ' , str(weight_kg))
2019-10-22 16:50
#80
 | 
Czech Republic DemoroCZ 
print('Weight (kg): ' + str(weight_kg))
2019-10-22 16:51
Login or register to add your comment to the discussion.