-
Notifications
You must be signed in to change notification settings - Fork 0
/
guessing.rb
109 lines (81 loc) · 1.47 KB
/
guessing.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
def calculation(num1, num2)
puts(num1*num2)
puts(num1/num2)
end
calculation(10,2)
def ShowStudent(name, age)
puts("Hello " + name + ", you are " + age.to_s + " years old!")
end
ShowStudent("Steve", 80)
n = 50
while n < 200
puts(n)
n += 1
end
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for i in numbers do
if i % 4 == 0
puts i
end
end
n = 10
while n > 0
puts(n)
n -= 1
end
a = "*"
i = 1
while i < 10
puts(i * b)
i += 1
end
begin
#... process, may raise an exception
rescue =>
#... error handler
else
#... executes when no error
ensure
#... always executed
end
points_scored = 100.0
points_possible = 50
begin
grade = points_scored / points_possible
rescue TypeError
puts "There is an error"
else
puts "Your grade is #{grade}%"
ensure
puts "Compiling complete"
end
scores = [80.0, 85.0, 90.0, 95.0, 100.0]
possibles = [100.0, 100.0, 100.0, nil, 100.0]
grades = []
for i in 0..(scores.length-1)
grades[i] = scores[i] / possibles[i]
end rescue grades[idx = 0.0]
puts(grades)
my_age = 90
your_age = 50
begin
our_ages = my_age + your_age
rescue => TypeError
puts "There is an error"
else
puts "There is no error"
puts our_ages
end
# Compling complete
def sayhi
puts "Hello User"
end
sayhi()
my_age = 100
your_age = 100
puts(my_age==your_age)
if my_age == 90 or your_age == 90
puts "Atleast one statement is true"
else
puts "None of the statements is true"
end