-
Notifications
You must be signed in to change notification settings - Fork 0
/
methods_practice_problems.rb
98 lines (59 loc) · 2.14 KB
/
methods_practice_problems.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
# 1. Write a program that asks the user to enter a word, then prints that word with all capital letters.
puts "Problem 1: "
puts "Enter a word:"
word = gets.chomp
p word.upcase
# 2. Write a program that asks the user to enter a number, then prints "That's a big number" if the number is greater than 100.
puts "Problem 2: "
puts "Enter a number:"
number = gets.chomp
if number.to_i > 100
p "That's a big number"
end
# 3. Write a program that asks the user to enter two numbers, then prints the numbers added together.
puts "Problem 3: "
puts "Enter two numbers:"
number_one = gets.chomp
number_two = gets.chomp
p number_one.to_i + number_two.to_i
# 4. Write a program that asks the user to enter a word, then prints that word in reverse order.
puts "Problem 4: "
puts "Enter a word:"
word = gets.chomp
p word.reverse
# 5. Write a program that asks the user to enter a number, then prints the number times 10.
puts "Problem 5: "
puts "Enter a number:"
number = gets.chomp
p number.to_i * 10
# 6. Write a program that asks the user to enter two words, then prints both words on the same line in all capital letters.
puts "Problem 6: "
puts "Enter two words:"
word_one = gets.chomp
word_two = gets.chomp
puts "#{word_one.upcase} #{word_two.upcase}"
# 7. Write a program that asks the user to enter a word, then prints the number of letters in the word.
puts "Problem 7: "
puts "Enter a word:"
word = gets.chomp
p word.length
# 8. Write a program that asks the user to enter a number, then prints "That's a negative number" if the number is less than 0.
puts "Problem 8: "
puts "Enter a number:"
number = gets.chomp
if number.to_i < 0
p "That's a negative number"
end
# 9. Write a program that asks the user to enter two numbers, then prints the two numbers multiplied together.
puts "Problem 9: "
puts "Enter two numbers:"
number_one = gets.chomp
number_two = gets.chomp
p number_one.to_i * number_two.to_i
# 10. Write a program that asks the user to enter a word, then prints "That's a long word" if the word has more than 5 letters.
puts "Problem 10: "
puts "Enter a word:"
word = gets.chomp
if word.length > 5
p "That's a long word."
end