#methods with arguments
def ask(question,answer)
i = 0
puts question
ans=gets.chomp.to_i
if ans==answer
@true+=1
puts "correct"
else
puts "wrong answer"
end
end
question=['what is 8+6','5*4?','7-4?','3*5','9/3']
answer=[14,20,3,15,3]
@true=0
for i in 0..4
ask(question[i],answer[i])
end
puts "true answer : #@true"
def ask(question,answer)
i = 0
puts question
ans=gets.chomp.to_i
if ans==answer
@true+=1
puts "correct"
else
puts "wrong answer"
end
end
question=['what is 8+6','5*4?','7-4?','3*5','9/3']
answer=[14,20,3,15,3]
@true=0
for i in 0..4
ask(question[i],answer[i])
end
puts "true answer : #@true"
OUTPUT:
what is 8+6
3
wrong answer
5*4?
20
correct
7-4?
3
correct
3*5
15
correct
9/3
3
correct
true answer : 4
No comments:
Post a Comment
if you have any query regarding geek languages,
email on arora.ratul@gmail.com