-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmethods_practice_problems.rb
89 lines (59 loc) · 2.25 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
# 1. Write a program that asks the user to enter a word, then prints that word with all capital letters.
# puts "Please enter a word:"
# word = gets.chomp.upcase
# puts word
# 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 "Please enter a number:"
# number = gets.chomp.to_i
# if number > 100
# puts "That's a big number"
# end
# 3. Write a program that asks the user to enter two numbers, then prints the numbers added together.
# numbers = []
# 2.times do
# puts "Please enter a number:"
# number = gets.chomp.to_i
# numbers << number
# end
# puts numbers[0] + numbers[1]
# 4. Write a program that asks the user to enter a word, then prints that word in reverse order.
# puts "Please enter a word:"
# word = gets.chomp
# puts word.reverse
# 5. Write a program that asks the user to enter a number, then prints the number times 10.
# puts "Please enter a number:"
# number = gets.chomp.to_i
# puts number * 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.
# words = []
# 2.times do
# puts "Please enter a word:"
# word = gets.chomp
# words << word
# end
# puts words[0].upcase + " " + words[1].upcase
# 7. Write a program that asks the user to enter a word, then prints the number of letters in the word.
# puts "Please enter a word:"
# word = gets.chomp
# puts 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 "Please enter a number:"
# number = gets.chomp.to_i
# if number < 0
# puts "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.
# numbers = []
# 2.times do
# puts "Please enter a number:"
# number = gets.chomp.to_i
# numbers << number
# end
# puts numbers[0] * numbers[1]
# 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 "Please enter a word:"
# word = gets.chomp
# if word.length > 5
# puts "That's a long word"
# end
# SOLUTIONS: https://gist.github.com/peterxjang/1539a3ad79728ba4fb68dd8d07279c29