Flyp Posted October 9, 2019 at 09:45 PM Report Share #616333 Posted October 9, 2019 at 09:45 PM Exercício 1: Escreva uma função em Python, chamada dias_mes, que recebe dois inteiros positivos, mes e ano, tais que 1 <= mes <= 12. A função deve devolver o número de dias do mês mes do ano ano. Use o seguinte algoritmo para determinar o número de dias: Se o mês for 2, então o número de dias será 29 ou 28, consoante o ano seja bissexto ou não, respetivamente. Um ano é bissexto se for divisível por 4 e não for divisível por 100, ou se for divisível por 400. Os restantes meses têm 31 dias se forem ímpares e menores ou iguais a 7, ou se forem pares e maiores ou iguais a 8. Caso contrário têm 30 dias. Por exemplo, >>> dias_mes(2, 1984) 29 >>> dias_mes(2, 1900) 28 >>> dias_mes(2, 2000) 29 >>> dias_mes(3, 2000) 31 >>> dias_mes(11, 2000) 30 Assuma que os valores passados à função estão sempre correctos. As suas funções devem DEVOLVER valores e NÃO escrevê-los. Assim, não deve utilizar instruções “print”, mas sim instruções “return”. Para se certificar deste aspecto, faça os seguintes testes: >>> isinstance(dias_mes(12,2019), int) True Link to comment Share on other sites More sharing options...
JoãoInacio Posted October 9, 2019 at 09:51 PM Report Share #616334 Posted October 9, 2019 at 09:51 PM (edited) Nunca estudei python para te ajudar a 100% mas já pensaste criar um/vários ciclos if and else. Edited October 9, 2019 at 09:51 PM by JoãoInacio Link to comment Share on other sites More sharing options...
M6 Posted October 10, 2019 at 10:01 AM Report Share #616335 Posted October 10, 2019 at 10:01 AM @Flyp, fiquei sem saber concretamente qual a tua dúvida ou problema. Coloca as tuas questões, dúvidas e problemas de forma clara e concreta para que te possam ajudar. 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
Flyp Posted October 10, 2019 at 10:19 AM Author Report Share #616336 Posted October 10, 2019 at 10:19 AM Eu estou iniciando programação, nunca programei, não estou entendo a lógica Link to comment Share on other sites More sharing options...
M6 Posted October 10, 2019 at 10:38 AM Report Share #616337 Posted October 10, 2019 at 10:38 AM Mas não compreendes o algoritmo, é isso? 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
Flyp Posted October 10, 2019 at 12:49 PM Author Report Share #616339 Posted October 10, 2019 at 12:49 PM Sim Link to comment Share on other sites More sharing options...
M6 Posted October 10, 2019 at 03:38 PM Report Share #616341 Posted October 10, 2019 at 03:38 PM Consegues compreender o que quer dizer "os meses têm 31 dias se forem ímpares e menores ou iguais a 7, ou se forem pares e maiores ou iguais a 8."? 1 Report 10 REM Generation 48K! 20 INPUT "URL:", A$ 30 IF A$(1 TO 4) = "HTTP" THEN PRINT "400 Bad Request": GOTO 50 40 PRINT "404 Not Found" 50 PRINT "./M6 @ Portugal a Programar." Link to comment Share on other sites More sharing options...
Flyp Posted October 10, 2019 at 10:27 PM Author Report Share #616343 Posted October 10, 2019 at 10:27 PM def bissexto(ano): return (ano % 4 == 0 and (ano % 400 == 0 or ano % 100 != 0)) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now