+ 1

String and algebra

How to print a thing ,which contains strings and numbers that have been defined?

31st Dec 2017, 6:22 AM
Nathan Lo
Nathan Lo - avatar
5 Respostas
+ 1
You have to transform integers to string with "str()" and concatenate strings with the plus symbol: + If I rewrite your print, it would be: print("While" + str(c) + " degree Celsius,\nit is" + str( ((9 / 5) * c + 32) ) + " degree Farenheit!!!") Note that str(c) just returns the value of c like a string but it doesn't change the type of c.
31st Dec 2017, 1:12 PM
Sebastián Zapata
Sebastián Zapata - avatar
+ 2
Maybe I didn't understand well your question but, if you want to print the result of the string "5 + 4" , you can call the "eval" function. >>> print(eval("5 + 4")) 9
31st Dec 2017, 6:37 AM
Sebastián Zapata
Sebastián Zapata - avatar
+ 1
string = "Nathan" int = 15 print(string + str(int)) //output: Nathan15 print(string , str(int)) //output: Nathan 15 I mean, you should convert it to string using str() function
31st Dec 2017, 6:37 AM
Mustafa K.
Mustafa K. - avatar
0
I understood now :) jajajaj
31st Dec 2017, 6:38 AM
Sebastián Zapata
Sebastián Zapata - avatar
0
I have a problem with this thing,and I don't know how to fix the "c" word that I had defined before: c=0 while True: print("while" 'c' "degree Celsius,\nit is" '((9/5)*c+32)' "degree Fahrenheit!!!") c=c+1 if c>=100: print("out of calculation") break print("finished")
31st Dec 2017, 8:37 AM
Nathan Lo
Nathan Lo - avatar