Seja um vetor declarado por:
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
notas = [] | |
# registra todas as 10 notas | |
for i in range(1, 11): | |
nota = float(input("Insira a nota do {}º aluno: ".format(i))) | |
notas.append(nota) | |
# calcula a média | |
media = sum(notas)/len(notas) |
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 int_to_bin(numero, bit=1, string=''): | |
str_bit = '1' if bool(numero & bit) else '0' | |
string = str_bit + string | |
if bit > numero: | |
return string | |
else: | |
return int_to_bin(numero, bit << 1, string) | |
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
function convert_coord_to_dms (lat, lon) { | |
/* | |
Se Lat é positivo é Norte, senão Sul | |
Se Long é positivo é Leste, senão Oeste | |
*/ | |
var lat_orientation = lat < 0 ? "S" : "N", | |
lon_orientation = lat < 0 ? "W" : "E"; | |
function get_dms(decimal) { |
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
function convert_coord_to_dms (lat, lon) { | |
/* | |
Se Lat é positivo é Norte, senão Sul | |
Se Long é positivo é Leste, senão Oeste | |
*/ | |
var lat_orientation = lat < 0 ? "S" : "N", | |
lon_orientation = lat < 0 ? "W" : "E"; | |
function get_dms(decimal) { |
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
function valid_date(str_data) { | |
var regex = /^\d{2}\/\d{2}\/\d{4}$/, | |
d, m, y; | |
str_data = str_data.trim(); | |
if (!regex.test(str_data)) { | |
return false | |
} |
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
// jQuery version | |
$(document).on('click', '.js-line-number', function(event){ | |
var elem = $(this).next('.js-file-line'), | |
bg_color = elem.css('backgroundColor'), | |
color_active = 'rgb(248, 238, 199)'; | |
elem.css('backgroundColor', bg_color === color_active ? 'rgba(0, 0, 0, 0)' : color_active); | |
}); | |
var elem = $(document.location.hash).trigger('click'); |
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
<? | |
// | |
// This is the result of about an hour's delving into PHP's hairy-ass serialization internals. | |
// PHP provides a session_decode function, however, it's only useful for setting the contents of | |
// $_SESSION. Say, for instance, you want to decode the session strings that PHP stores in its | |
// session files -- session_decode gets you nowhere. | |
// | |
// There are a bunch of nasty little solutions on the manual page[1] that use pretty hairy regular | |
// expressions to get the job done, but I found a simple way to use PHP's unserialize and recurse | |
// through the string extracting all of the serialized bits along the way. |
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
<?php | |
function teste_unicode_regex($value) { | |
$min = (preg_match("/\\p{Ll}/u", $value)) ? "Sim" : "Não" ; | |
$mai = (preg_match("/\\p{Lu}/u", $value)) ? "Sim" : "Não" ; | |
$num = (preg_match("/\\d/", $value)) ? "Sim" : "Não" ; | |
echo <<<TEXT | |
=== $value === |
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
// http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibFormula.html | |
function fibonacci_nth(i){ | |
var v5 = Math.sqrt(5), | |
Phi = ( v5 + 1 ) / 2, | |
phi = Phi-1; | |
return Math.round( Math.pow(Phi, i) / v5 - Math.pow(-phi, i) / v5 ); | |
} |