Skip to content

Commit 5fdd4c1

Browse files
committed
Initial commit
0 parents  commit 5fdd4c1

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

Letters/strings.rb

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
puts 'Hello, world!'
3+
puts ''
4+
puts 'Good-bye!'
5+
6+
#Adding strings with no space:
7+
puts 'I like' + 'apple pie.'
8+
9+
#Adding strings with spaces:
10+
puts 'I like ' + 'apple pie.'
11+
puts 'I like' + ' apple pie.'
12+
13+
# Multiplying strings:
14+
puts 'blink ' * 4
15+
16+
# Difference between numbers and digits
17+
18+
puts 12 + 12
19+
puts '12' + '12'
20+
puts '12 + 12'
21+
22+
puts 2 * 5
23+
puts '2' * 5
24+
puts '2 * 5'
25+
26+
# Problems = things that didn't work
27+
28+
#1. Add a number to a string puts '12' + 12
29+
#2. Multiply strings puts '2' * '5'
30+
#3. Order of multiplying matters puts 5*'pig'
31+
#4. Escape the apostrophe. This don't work: puts 'you're swell!'. But this does:
32+
puts 'You\'re swell!'
33+
#5. Examples of escaping in strings:
34+
puts 'You\'re swell!'
35+
puts 'backslash at the end of a string: \\'
36+
puts 'up\\down'
37+
puts 'up\down'

Numbers/calc.rb

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
puts 1.0 + 2.0
2+
puts 2.0 * 3.0
3+
puts 5.0 - 8.0
4+
puts 9.0 / 2.0
5+
6+
puts 1+2
7+
puts 2*3
8+
puts 5-8
9+
puts 9/2
10+
11+
puts 5 * (12-8) + -15
12+
puts 98 + (59872 / (13 * 8)) * -51
13+
14+
15+

Numbers/exercices02.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# Hours in a year. How many hours are in a year?
3+
4+
puts "A year has #{365*24} hours, or #{366*24} hours if it's a leap year."
5+
6+
# Minutes in a decade. How many minutes are in a decade?
7+
8+
puts "A decade has #{60*24*(365*10+2)} or #{60*24*(365*10+3)} minutes."
9+
10+
# Your age in seconds. How many seconds old are you?
11+
12+
puts "I am #{60*60*24*(365*34 + (34/4))} seconds old."
13+
14+
# If I'm 1.160 million seconds old, how old am I?
15+
16+
puts "You have #{1160000000/(60*60*24*365)} years."

Variables and Assignment/variables.rb

Whitespace-only changes.

0 commit comments

Comments
 (0)