Using a Variable Inside the String

sveemani at gmail.com sveemani at gmail.com
Tue May 7 13:34:21 EDT 2019


On Tuesday, May 7, 2019 at 10:13:42 PM UTC+5:30, Rob Gaddi wrote:
> On 5/7/19 7:55 AM, sveemani at gmail.com wrote:
> > On Tuesday, May 7, 2019 at 1:20:49 AM UTC+5:30, MRAB wrote:
> >> On 2019-05-06 19:44, sveemani at gmail.com wrote:
> >>> Hi all,
> >>>
> >>> I am new learner of python programming and I am into my basics.
> >>> I got  struck with the code in   a sample  program and refer the same with IDE and  googling which did not help me for more than a day.
> >>>
> >>> What is  wrong with  my last 2  lines?
> >>> what I am missing?
> >>>
> >>> ##################
> >>> my_name = 'Veera'
> >>> my_age = 40 #  Actually 42
> >>> my_height = 155 # Inches
> >>> my_weight = "80" # checking the double quotes
> >>> my_eyes = 'brown'
> >>> my_teeth = 'white'
> >>> my_hair =  'black'
> >>>
> >>> print(f"Let's  talk  about  {my_name}.")
> >>> print(f"He's {my_height} inches  tall.")
> >>> print(f"He's {my_weight} weight heavy.")
> >>> print("Actually  thats  not too Heavy.")
> >>>
> >>> print(f"He's  got {my_eyes} eyes and {my_hair}  hair.")
> >>> print(f"His  teeth are actually  {my_teeth} depending on the  coffee.")
> >>>
> >>>
> >>> ### this  line are where I Struck #####
> >>
> >> 'my_age' and 'my_height' are numbers, but 'my_weight' is a string
> >> (why?). You can't add a number and a string together.
> >>
> >>> total =   my_age + my_height + my_weight
> >>> print(f"If I add {my_age}, {my_height}, and {my_weight} I get  {total} .")
> >>>
> >>> ##########################
> >>>
> > 
> > 
> > Thanks . It worked  .
> > Will  have to read more on strings to get the exact total value..
> > 
> 
> The comment can't be ignored because it's sitting there flagging your 
> problem.  Strings (in single or double quote) are strings; a sequence of 
> characters as used to write words.  Numbers are numbers.  You can't add 
> them together.
> 
> This over here is my friend Bob.  What's 31 + 18 + Bob?  The question 
> makes no sense, because the operation of addition isn't defined in such 
> a way that allows you to add numbers to human beings.  You can't add 
> them to strings either.
> 
> -- 
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com
> Email address domain is currently out of order.  See above to fix.


###
Thanks for your Inputs.
Its  a self  Exercise  for learning of string  .and I realized the error,   when I got the output of total as 4015580. Then I insert the age and height into  strings"" in declaring , so that the  total is  as expected. 




More information about the Python-list mailing list