Alguns algoritmos Passeio aleatório Método de Newton Passeio aleatório Algoritmo: começar no centro da janela atirar moeda ao ar; cara → virar 90 graus à esquerda coroa → virar 90 graus à direita dar 50 passos em frente se a tartaruga sair da janela, parar Análise: dificuldade: saber se se saiu da janela solução: diferir, encapsulando numa função create a window and a turtle while the turtle is still in the window: generate a random number between 0 and 1 if the number == 0 (heads): turn left else: turn right move the turtle forward 50 João Pedro PEDROSO Introdução à Programação - minor
27
Embed
Método de Newton Passeio aleatório - FCUPjpp/ip/slides-08.pdf · Alguns algoritmos Passeio aleatório Método de Newton Passeio aleatório Algoritmo: começar no centro da janela
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Alguns algoritmosPasseio aleatórioMétodo de Newton
Passeio aleatório
Algoritmo:começar no centro da janelaatirar moeda ao ar;
cara → virar 90 graus àesquerdacoroa → virar 90 graus à direita
dar 50 passos em frentese a tartaruga sair da janela,parar
Análise:
dificuldade: saber se se saiu dajanela
solução: diferir, encapsulandonuma função
create a window and a turtle
while the turtle is still in the window:generate a random number between 0 and 1if the number == 0 (heads):
turn leftelse:
turn rightmove the turtle forward 50
João Pedro PEDROSO Introdução à Programação - minor
Alguns algoritmosPasseio aleatórioMétodo de Newton
Versão 1
(versão simplista de isInScreen: 90% de probabilidade de a tartarugaestar na janela)import randomimport turtle