
String arithmetic
show image
As you can do arithmetic on numbers, you can also do arithmetic on strings! Let's try to add two strings and see what puts does with that:
string 'I Like '
string 'Tee, coffe and cigarette'
so you can code in ruby
puts 'I Like' + 'Tee,coffe and cigarette'
there is a number 420
puts 'me' + 420
difference between numbers and digits. 10 is a number, but '10' is a string of two digits
let's play with this for a while
puts 10 + 10
puts '10' + '10'
puts '10 + 10'
puts 2 * 8
puts '3' * 10
puts '5 * 15'
puts '10' * 10
puts '5' * '10'
there is show u problem for last tow line program #
your code in ruby language
puts 'I Like' + 'Tee,coffe and cigarette'
puts 'me' + '420'
puts 10 + 10
puts '10' + '10'
puts '10 + 10'
puts 2 * 8
puts '3' * 10
puts '5 * 15'
your result
>ruby 1.rb
I LikeTee,coffe and cigarette
me420
20
1010
10 + 10
16
3333333333
5 * 15
>Exit code: 0
No comments:
Post a Comment