I wrote this program in ruby:
"Nonna = CIAO CARO NIPOTINO, COME STAI??"
puts "Tu = Bene nonna, ma non urlare"
puts "Nonna = COME DICI, PARLA PIU' FORTE!!"
def ask()
a = gets.chomp
ok = a.upcase()
numero = rand(100)
ciao = "CIAO NONNA!"
if a == ok
puts "NO CARO, NON LO VEDO DAL " + numero
ask
else
puts "COSA HAI DETTO? NON CI SENTO, RIPETI!"
ask
end
end
ask()
(Excuse the Italian) However, when I run it it gives me this error:
Traceback (most recent call last):
2: from vecchia.rb:20:in `<main>'
1: from vecchia.rb:11:in `chiede'
vecchia.rb:11:in `+': no implicit conversion of Integer into String (TypeError)
What can I do?
It's complaining about a number concatened to a string. Two simple ways
1) turn the number into a string
puts "NO CARO, NON LO VEDO DAL " + numero.to_s
or 2) interpolate the number into the string
puts "NO CARO, NON LO VEDO DAL #{numero}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With