-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex30.rb
47 lines (36 loc) · 1.07 KB
/
ex30.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#Exercise 30: Else and If
people = 45
cars = 26
trucks = 12
if cars > people
puts "We should take the cars."
elsif cars < people
puts "We should not take the cars."
else
puts "We can't decide."
end
if trucks > cars
puts "That's too many trucks."
elsif trucks < cars
puts "Maybe we could take the trucks."
else
puts "We still can't decide."
end
if people > trucks
puts "Alright, let's just take the trucks."
else
puts "Fine, let's stay home then."
end
#1) Try to guess what elsif and else are doing.
#elsif tells that if the first statement is not true but this one is, then run the block of code.
#The else tells if the previous statements are not true then run the block of code.
#2) Change the numbers of cars, people, and trucks and then trace through each if-statement to see what will be printed.
#3) Try some more complex boolean expressions like cars > people || trucks < cars.
if cars > people || trucks < cars
puts "We should share our cars"
end
if cars < people && trucks
puts "Fine, less contaminant shit"
else
puts "Welcome to Trump paradise"
end