Com os conhecimentos aplicados anteriormente, crie uma calculadora que dado dois valores e um número que corresponde a uma operação (constante), retorne o resultado da operação
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def char_counter(text, char) | |
text_splited = text.split(' ').join('') | |
text_splited.each_char.tally[char] | |
end | |
puts 'Qual o texto que quer usar:' | |
text = gets.chomp | |
puts 'Qual caracter quer contar:' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'net/http' | |
https = Net::HTTP.new('example.com', 443) | |
https.use_ssl = true | |
response = https.get('/') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts 'Digite seu número:' | |
phone_number = gets.chomp | |
whats = '(' << phone_number[0..1] << ') ' << phone_number[2] << ' ' << phone_number[3..6] << '-' << phone_number[7..] | |
if whats.match?(/\(\d{2,}\) \d{1} \d{4,}\-\d{4}/) and phone_number.size == 11 | |
puts "Seu Whatsapp é #{whats}" | |
else | |
puts 'Número inválido' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative 'produto' | |
require_relative 'mercado' | |
produto = Produto.new | |
produto.nome = 'Farinha de trigo' | |
produto.preco = 4.0 | |
Mercado.new(produto.nome, produto.preco).comprar | |
livro = Produto.new | |
livro.nome = 'Livro' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'cpf_cnpj', '~> 0.5.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = [] | |
puts 'Digite 3 números:' | |
3.times do | |
num = gets.chomp.to_i | |
numbers.append(num) | |
end | |
numbers.each do |num| | |
puts num**3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('Digite seu nome: ') | |
name = gets.chomp | |
print('Digite seu sobrenome: ') | |
lastname = gets.chomp | |
print('Digite sua idade: ') | |
age = gets.chomp.to_i | |
puts "Olá #{name} #{lastname}! Seja bem vindo! Sua idade é #{age} anos." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(args: Array<String>) { | |
val n = readLine()!!.toInt() | |
var sum : Int | |
var t1: Int = 0 | |
var t2: Int = 1 | |
for (i in 1..(n-1)) { |