所以我只是制作了一个随机代码生成器并添加了一个循环,这样你就可以再次运行而不再运行它。但显然当我在最后输入“是”时会再次输入,但是当我输入“否”时仍会再次输入。
这是我的代码:
loop do
puts "Hello. I am a random code generator. PLease type in how many digits you want"
b = gets.chomp.to_i
a = rand *10**b
puts "Your random code is #{a.to_i}"
puts "Would you like to go again?"
x = gets
if x == 'no'
break
end
end
答案 0 :(得分:1)
loop do
puts "Hello. I am a random code generator. PLease type in how many digits you want"
b = gets.chomp.to_i
a = rand *10**b
puts "Your random code is #{a.to_i}"
puts "Would you like to go again?"
x = gets.chomp
if x == 'no'
break
end
end