-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Magda Rocha
committed
Oct 22, 2023
1 parent
ed02441
commit e1213a9
Showing
13 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Ler o sexo de uma pessoa mas só aceitar valores M e F | ||
# Caso esteja errado pedir para escrever de novo até ter um valor correto | ||
|
||
sexo = str(input(' Qual é o teu sexo?')).upper() | ||
|
||
while sexo != 'M' and sexo != 'F': | ||
sexo = input(' Escreva novamente o sexo ').upper() | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#Melhorar o jogo do desafio 28, onde o computador vai pensar num número entre 0 e 10. | ||
# O jogador vai tentar adivinhar até acertar, mostrando no final quantos palpites foram necessários para vencer | ||
|
||
import random | ||
|
||
numero_computador = random.randrange(1,10) | ||
|
||
escolha_do_jogador = int(input(' Adivinhe que número o computador pensou: ')) | ||
|
||
tentativas = 1 | ||
|
||
while escolha_do_jogador != numero_computador: | ||
escolha_do_jogador = int(input(' Erraste! Escolhe de novo: ')) | ||
|
||
tentativas = tentativas + 1 | ||
|
||
print (' Finalmente acertaste!') | ||
|
||
print (' Precisaste de {} tentativas '.format(tentativas)) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Ler dois valores e mostrar um menu no ecrã | ||
# 1 para somar, 2 para multiplicar, 3 para maior , 4 para novos numeros e 5 para sair do programa | ||
# O programa deve realizar a operação solicitada em cada caso | ||
|
||
valor1 = int(input(' Escreve um número: ')) | ||
valor2 = int(input(' Escreve outro número: ')) | ||
|
||
opcao = 0 | ||
|
||
while opcao != 5: | ||
print(' Escolha 1 para somar') | ||
print(' Escolha 2 para multiplicar') | ||
print(' Escolha 3 para saber qual o número maior') | ||
print(' Escolha 4 para escrever novos números') | ||
print(' Escolha 5 para sair') | ||
opcao = int(input(' Qual é a opção? ')) | ||
|
||
if opcao == 1: | ||
print(valor1 + valor2) | ||
elif opcao == 2: | ||
print(valor1 * valor2) | ||
elif opcao == 3: | ||
if valor1 > valor2: | ||
print(' O valor {} é maior. '.format(valor1)) | ||
else: | ||
print('O valor {} é maior'.format(valor2)) | ||
elif opcao == 4: | ||
valor1 = int(input(' Escreve um número: ')) | ||
valor2 = int(input(' Escreve outro número: ')) | ||
|
||
print (' Saiu! ') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Ler um número qualquer e mostrar o seu fatorial | ||
|
||
numero = int(input(' Escreve um número: ')) | ||
|
||
fatorial = numero | ||
|
||
while numero != 1: | ||
numero = numero - 1 | ||
fatorial = fatorial * numero | ||
|
||
print (' O fatorial é {}. '.format(fatorial)) | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Refazer o desafio 51, lendo o primeiro termo e a razão de uma PA | ||
# Mostrar os 10 primeiros termos da progressão usando while | ||
|
||
#TODO | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#TODO | ||
#Melhorar o desafio 61 perguntando ao utilizador se quer mostrar mais alguns termos. O programa encerra quando ele disser que quer mostrar zero termos. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Ler um número n inteiro qualquer e mostrar no ecrã os n primeiros elementos de uma sequÊncia fibonacci | ||
|
||
numero = int(input(' Escreve um número: ')) | ||
|
||
fibonacci = [0,1] | ||
|
||
while numero != len(fibonacci): | ||
proximo_elemento = fibonacci[-1] + fibonacci[-2] | ||
fibonacci.append(proximo_elemento) | ||
|
||
print(fibonacci) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#Ler varios numeros inteiros. O programa só para quando escrever o valor 999. | ||
#No fim mostrar quantos numero foram escritos e qual foi a soma entre eles(sem contar o 999) | ||
|
||
numero = 0 | ||
contagem = 0 | ||
soma = 0 | ||
|
||
while numero != 999: | ||
numero = int(input(' Escreva um número: ')) | ||
|
||
contagem = contagem + 1 | ||
soma = soma + numero | ||
|
||
contagem = contagem - 1 | ||
soma = soma - 999 | ||
|
||
print(' Escreveste {} números. '.format(contagem)) | ||
|
||
print(' A soma dos números é {}. '.format(soma)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#Ler vários numeros inteiros | ||
# Mostrar a média entre todos e qual o maior e menor | ||
# O programa deve perguntar À pessoa se quer continuar a escrever numeros | ||
|
||
numero = 0 | ||
media = 0 | ||
contagem = 0 | ||
soma = 0 | ||
maior_numero = 0 | ||
menor_numero = 9999999 | ||
pergunta = '' | ||
|
||
while pergunta != 'N': | ||
numero = int(input(' Escreve um número: ')) | ||
pergunta = input(' Quer continuar? [S/N] ').upper() | ||
|
||
contagem = contagem + 1 | ||
soma = soma + numero | ||
|
||
if numero > maior_numero: | ||
maior_numero = numero | ||
|
||
if numero < menor_numero: | ||
menor_numero = numero | ||
|
||
|
||
|
||
media = soma / contagem | ||
|
||
print(' A média dos numeros é {} '.format(int(media))) | ||
|
||
print(' O maior numero é {} '.format(maior_numero)) | ||
|
||
print('O menor numero é {} '.format(menor_numero)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Ler vários numeros inteiros. O programa só para quando escrever 999. | ||
# No fim mostrar quantos numeros foram digitados e qual foi a soma entre eles. | ||
|
||
numero = 0 | ||
contagem = 0 | ||
soma = 0 | ||
|
||
while True: | ||
numero = int(input(' Escreva um número: ')) | ||
if numero == 999: | ||
break | ||
contagem += 1 | ||
soma += numero | ||
|
||
print (f' Foram escritos {contagem} números e a soma deles é {soma}.') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#Mostrar a tabuada de vários numeros um de cada vez, para cada valor escrito pelo utilizador. | ||
# O programa é interrompido quando o numero solicitado for negativo | ||
|
||
|
||
|
||
while True: | ||
numero = int(input(' Escreve um número: ')) | ||
if numero < 0: | ||
break | ||
for i in range(1,11): | ||
tabuada = numero * i | ||
|
||
print (f' {numero} x {i} = {tabuada}') | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#Jogar par ou impar com o computador, o jogo é interrompido quando o jogador perder | ||
#Mostra o total de vitórias consecutivas no final do jogo | ||
|
||
import random | ||
|
||
vitoria = 0 | ||
|
||
while True: | ||
numero = int(input('Escreve um número: ')) | ||
par_impar = str(input(' Par ou impar? [P/I] ')).upper() | ||
|
||
numero_computador = random.randrange(1,11) | ||
print(f' O computador escolheu {numero_computador}') | ||
soma = numero + numero_computador | ||
|
||
if soma%2 == 0: | ||
if par_impar == 'P': | ||
print(' Ganhaste! ') | ||
vitoria += 1 | ||
else: | ||
print(' Perdeste ') | ||
|
||
break | ||
elif soma%2 == 1: | ||
if par_impar == 'I': | ||
print(' Ganhaste! ') | ||
vitoria += 1 | ||
else: | ||
print(' Perdeste ') | ||
|
||
break | ||
|
||
print(f'Venceu {vitoria} vezes') | ||
|
||
|
||
|
||
|
||
|
Empty file.