-
Notifications
You must be signed in to change notification settings - Fork 386
/
Copy path9_input_output_logic_string.rb
44 lines (38 loc) · 1.22 KB
/
9_input_output_logic_string.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
# Taken from http://pragprog.com/titles/fr_ltp/learn-to-program
#
# Write a Deaf Grandma program. Whatever you say to grandma (whatever
# you type in), she should respond with HUH?! SPEAK UP, SONNY!, unless
# you shout it (type in all capitals). If you shout, she can hear you
# (or at least she thinks so) and yells back, NO, NOT SINCE 1938!
# You can't stop talking to grandma until you shout BYE.
#
# Hint: Don't forget about chomp! "BYE\n" is not the same as "BYE"
# (check the String cheatsheet if you need)
#
# remember, you can try your program by going to the terminal and typing $ ruby 9_input_output_logic_string.rb
#
# example:
#
#
# USER: $ ruby 9_input_output_logic_string.rb
# USER: hi grandma.
# GRANDMA: HUH?! SPEAK UP, SONNY!
# USER: HI GRANDMA!
# GRANDMA: NO, NOT SINCE 1938!
# USER: bye
# GRANDMA: HUH?! SPEAK UP, SONNY!
# USER: BYE
def deaf_grandma
while true
input = gets.chomp
break if input == "BYE"
if input == input.upcase && input != ""
puts "NO, NOT SINCE 1938!"
else
puts "HUH?! SPEAK UP, SONNY!"
end
end
end
# This will call your code so you can run it from the terminal.
# But not call it otherwise, so that it will work with our tests.
deaf_grandma if $0 == __FILE__