Ejercicios :

  • Ingrese numero de caballo y mostrar en pantalla mediante aleatorios si ganaste o perdiste

class Pro
    def initialize()
    end
    def apuesta()
     puts"Por cual caballo escogerias"
     puts"1.Rocinante"
     puts"2.trueno"
     puts"3.comanche"
     puts"4.gitana"
     puts"5.sombra"
     puts"6.salvaje"
     print "===> "
      a=gets.to_i
      x=Random.new.rand(1..6)
     print"El caballo ganador es:"
     puts x
 if(a==x) then
        print "GANASTE !!"
      else
       print"PERDISTE :("
     end
  end
end
objeto=Pro.new
objeto.apuesta  
gets()
 end
end

objeto=H.new
objeto.operaciones
gets()
  • Imprimir un triangulo de asteriscos mediante ciclos for
class H
class Practica
def initialize()
 end
 def asteriscos()
    i=0 
    j=0
    n=15
    #-------------------------------------------------------------------------    
    #imprimir con asterisco for
       for j in j..n
        print "\t\t\t"
        #-------------------------------------------------------------------------    
          for i in 1..(n-j)
      print " "
          end
        #-------------------------------------------------------------------------    
        for i in 1..(2*j-1)
       if (i==1) or (i==2*j-1) or (j==n) then
                                 print "*"
                         else 
                                                             
                                 print" "
                         end   
#-------------------------------------------------------------------------   
        end
     print "\n"
     end
#-------------------------------------------------------------------------    
  end 
end
objeto = Practica.new()
objeto.asteriscos
gets()   
  • Convertir a numeros romanos
class H
  def initialize()
  end
  def numerosromanos()
       print "Ingrese un numero (1 al 19) para convertir: "
       numero=gets.to_i    
     unidades=numero%10
        numero=numero/10
       decenas=numero%10
      numero=numero/10
       puts "------------en romano------------"
                  case decenas
                       when 1 then print"X"
                       end
                  case unidades
                      when 1 then print"I"
                      when 2 then print"II"
                      when 3 then print"III"
                      when 4 then print"IV"
                      when 5 then print"V"
                      when 6 then print"VI"
                      when 7 then print"VII"
                      when 8 then print"VIII"
                      when 9 then print"IX"
                end
  end
end
objeto = H.new()
objeto.numerosromanos
gets() 
  • Segun el promedio saber su rendimiento
class H
  def initialize()
  end
  def rendimiento()

       puts"--------------------------------Ingrese 3 notas--------------------------------"
       print "Ingrese nota de trabajos:"
       t=gets.to_i
       print "Ingrese nota de medio ciclo:"
       m=gets.to_i
       print "Ingrese nota de fin de ciclo:"
       f=gets.to_i
       np=((0.5)*t) + ((0.2)*m) + ((0.3)*f)
       
        if (np<0 data-blogger-escaped-np="">20) then
            puts "Datos erroneos !!!!"
                elsif (np<=5) then
                      print "su promedio es "
                      print np
                      puts "  ; usted esta en un rendimiento pesimo"
                          elsif (np<=10) then 
                                  print "su promedio es "
                                  print np
                                  puts " ; usted esta en un rendimiento malo"
                                elsif (np<=15) then
                                        print "su promedio es "
                                        print np
                                     puts " ; usted esta en un rendimiento regular"
                                       else 
                                        print "su promedio es "
                                        print np 
                                        puts " ; usted esta en un rendimiento bueno"
                 end
        end
end
objeto = H.new()
objeto.rendimiento
gets() 

0 comentarios:

Publicar un comentario