anonymous
  • anonymous
Comments on my ps2b code? http://pastebin.com/rCX2nVh7 NOTE: You'll see a mix of string concatenation and string formatting with '%i' and '%s' in the printed answers at the end. I was originally going to do it all in string formatting but I kept getting an error saying that Python couldn't print the integers in the string. The syntax was solid though, so I'm guessing this had something to do with those integers being floats? I just changed it so the numbers were converted to string first and then concatenated to get past the error. Never bothered to change the first print statement too.
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
My bad! This code is actually from ps1b, not ps2b! LOL, forgot the whole counting-from-zero thing.
carlsmith
  • carlsmith
Hi there. Just to point out quickly; floats are not actually integers, ints are the non-floats, the whole numbers. Anyway, have you learnt how to use the string .format() method yet? You can use that for creating new strings really well. a = 50 b = 5.5 c = 'The number {0} is an example of an int, whilst {1} is a float.'.format(a, b) You can also use the str() function within concatenation expressions. cheesy_pop = 'ABC ~ It's easy like ' + str(123) I'll try and find time to have a proper look through your code soon, I'm just a bit busy at the moment.
anonymous
  • anonymous
Right! I was using 'integer' loosely there for a second without regard for it's Python meaning, my bad! And I haven't yet learnt that method. I'm going to look into that right away. Thanks man.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

carlsmith
  • carlsmith
No worries.
carlsmith
  • carlsmith
You will get errors if you try and concatenate a non-string into a string expression. >>>string = 'abc' + 5 # this will throw one But the print statement will convert non-strings implicitly. >>>print 'abc', 5 abc 5 Note that print will not convert part of an expression. It just converts floats and ints and stuff to strings when they are single arguments in their own right >>>print 'abc' + 5 # another error coming up >>>print 'abc', 5, 5.5 abc 5 5.5 You can do legal expressions. >>>print 'abc' + 'cde', 5 + 5 abcdef 10 I personally never use %formatting, I never like it. I just use the format method or concatenation with str() calls. Add parenthesis, backslashes, and triple-quotes, and you can avoid ever using %formatting. a = 'Bob' print 'Hello ' +str(a)+ ' how are you?'

Looking for something else?

Not the answer you are looking for? Search for more explanations.