【发布时间】:2013-09-08 00:59:19
【问题描述】:
我创建了一个简单的程序来询问体育迷一些信息。这是我到目前为止的代码:
puts "What's your favorite pro sport?"
favorite_sport = gets.chomp
puts "Who's your favorite team in the #{favorite_sport}?"
favorite_team = gets.chomp
puts "What city are they from?"
team_city = gets.chomp
puts "Who's your favorite player in the #{favorite_team} roster?"
favorite_player = gets.chomp
puts "What position does #{favorite_player} play?"
player_position = gets.chomp
puts "How many years has #{favorite_player} played in the #{favorite_sport}"
years_experience = gets.chomp
fan_info = [favorite_sport, favorite_team, team_city, favorite_player, player_position, years_experience]
puts fan_info
我想让程序输出 fan_info,字符串的第一个字母大写。我该怎么做呢?我知道我必须使用 capitalize 方法,但我无法实现。
下面是输入输出的例子:
What's your favorite pro sport?
NFL
Who's your favorite team in the NFL?
Seahawks
What city are they from?
seattle
Who's your favorite player in the Seahawks roster?
wilson
What position does wilson play?
qb
How many years has wilson played in the NFL
1
NFL
Seahawks
seattle
wilson
qb
1
【问题讨论】:
-
对于用户输入
"NFL",你希望输出是"Nfl"还是"NFL"? -
好收获!是的,我确实想把它留给 NFL。即使没有输入全部大写。
标签: ruby arrays methods capitalization