DATA STRUCTURES FORM/secret identity


#1



My code is always wrong.
Who can help me please ?


https://www.codecademy.com/fr/courses/ruby-beginner-fr-FR-yh7nf/2/4?curriculum_id=535e93005d81962043000001


identites_secretes = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}
identités_secretes.each do |x, y|
puts "#{The Batman}: #{Bruce Wayne}"
puts "#{Superman}: #{Clark Kent}"
puts "#{Wonder Woman}: #{Diana Prince}"
puts "#{Freakazoid}: #{Dexter Douglas}"
end


Replace this line with your code.


#2

Here:

puts "#{The Batman}: #{Bruce Wayne}"
puts "#{Superman}: #{Clark Kent}"
puts "#{Wonder Woman}: #{Diana Prince}"
puts "#{Freakazoid}: #{Dexter Douglas}"

you have hardcoded things to print out. This is okay, but one of the core principles of programming is DRY (don't repeat yourself). You have this data in variable identites_secretes, there is no need to repeat that.

Now you have to use method each to iterate through every key: value pair and print it out.

identites_secretes.each do |x, y|
    puts "#{x}: #{y}"
end

#3

Good evenening Factoradic and thanks.

identites_secretes = {
"The Batman" => "Bruce Wayne",
"Superman" => "Clark Kent",
"Wonder Woman" => "Diana Prince",
"Freakazoid" => "Dexter Douglas"
}
identités_secretes.each do |x, y|
puts "#{x}: #{y}"
end

But the code doesn't work :

undefined local variable or method `identités_secretes' for #
Oups, merci de réessayer. Vous n'avez rien affiché dans la console.

So i don't understand and it's driving me crazy.


#4

Now it works.
I had an aacent on the e of identites.

Thank you.


#5

Oh, Python does not support diacritical marks in the names of objects. And that is why here:

identités_secretes.each

you have to change é to e.


#6

You're welcome :slight_smile:

Glad it works!