Sep-09-2019, 03:55 AM
EXERCISE:
The following function allows you to find out the day of the week for a specific date.
The date is supplied in the form of three integer parameters and the function returns
0 for Sunday, 1 for Monday, 2 for Tuesday, etc. Write a program
to print on the screen the calendar of a full month, corresponding to a
any month and year based on the function provided. Consider that the week
It starts on Sunday.
ONLY using: if, elif, else, and, or, not, while, break, continue, for, in, range(), lambda.
NO lists or modules.
I made an incomplete program that some parts are in spanish, but I think you can get around the meaning.
The following function allows you to find out the day of the week for a specific date.
The date is supplied in the form of three integer parameters and the function returns
0 for Sunday, 1 for Monday, 2 for Tuesday, etc. Write a program
to print on the screen the calendar of a full month, corresponding to a
any month and year based on the function provided. Consider that the week
It starts on Sunday.
def diadelasemana(dia,mes,año): if mes < 3: mes = mes + 10 año = año – 1 else: mes = mes – 2 siglo = año // 100 año2 = año % 100 diasem = (((26*mes-2)//10)+dia+año2+(año2//4)+(siglo//4)-(2*siglo))%7 if diasem < 0: diasem = diasem + 7 return diasemRESTRICTIONS:
ONLY using: if, elif, else, and, or, not, while, break, continue, for, in, range(), lambda.
NO lists or modules.
I made an incomplete program that some parts are in spanish, but I think you can get around the meaning.
# Author: KoFu def diadelasemana(dia,mes,año): """ Permite averiguar el día de la semana para una fecha introducida por el usuario.""" if mes < 3: mes = mes + 10 año = año - 1 else: mes = mes - 2 siglo = año // 100 año2 = año % 100 diasem = (((26*mes-2)//10)+dia+año2+(año2//4)+(siglo//4)-(2*siglo))%7 if diasem < 0: diasem = diasem + 7 return diasem def validarfecha(x,y,z): """ Permite validar la fecha devolviendo true or false.""" if(y==1 or y==3 or y==5 or y==7 or y==8 or y==10 or y==12): max1=31 elif(y==4 or y==6 or y==9 or y==11): max1=30 elif(z%4==0 and z%100!=0 or z%400==0): max1=29 else: max1=28 if(y<1 or y>12): valida = False elif(x<1 or x>max1): valida = False else: valida = True return valida; def graficar_calendario(x,y,z): """ Devuelve un calendario del mes de la fecha ingresada por el usuario""" # Asociamos la variable max1 con la cant de dias del los meses correspondientes if(y==1 or y==3 or y==5 or y==7 or y==8 or y==10 or y==12): max1=31 elif(y==4 or y==6 or y==9 or y==11): max1=30 elif(z%4==0 and z%100!=0 or z%400==0): max1=29 else: max1=28 ## Empieza a graficar if (y==1): print ("Enero") elif (y==2): print ("Febrero") elif (y==3): print ("Marzo") elif (y==4): print ("Abril") elif (y==5): print ("Mayo") elif (y==6): print ("Junio") elif (y==7): print ("Julio") elif (y==8): print ("Agosto") elif (y==9): print ("Septiembre") elif (y==10): print ("Octubre") elif (y==11): print ("Noviembre") elif (y==12): print ("Diciembre") print ("Do","Lu","Ma","Mi","Ju","Vi","Sa") # for i in range(1, max1+1, 1): # if (diadelasemana(1,y,z) == 0): # print (0+i, end= " ") # x +=1 # if (diadelasemana(1,y,z) == 1): # print (0+i, end= " ") # x +=1 # if (diadelasemana(1,y,z) == 2): # print (0+i, end= " ") # x +=1 # if (diadelasemana(1,y,z) == 3): # print (0+i, end= " ") # x +=1 # if (diadelasemana(1,y,z) == 4): # print (0+i, end= " ") # x +=1 # if (diadelasemana(1,y,z) == 5): # print (0+i, end= " ") # x +=1 # if (diadelasemana(1,y,z) == 6): # print (0+i, end= " ") # x +=1 # if (diadelasemana(1,y,z) == 7): # print (0+i, end= " ") # x +=1 for i in range(1, max1+1, 7): if (diadelasemana(1,y,z) == 0): print (0+i) for i in range(2, max1+1, 7): if (diadelasemana(1,y,z)+1 == 1): print (0+i) for i in range(3, max1+1, 7): if (diadelasemana(1,y,z)+2 == 2): print (0+i) for i in range(4, max1+1, 7): if (diadelasemana(1,y,z)+3 == 3): print (0+i) for i in range(5, max1+1, 7): if (diadelasemana(1,y,z)+4 == 4): print (0+i) for i in range(6, max1+1, 7): if (diadelasemana(1,y,z)+5 == 5): print (0+i) for i in range(1, max1+1, 7): if (diadelasemana(1,y,z)+6 == 6): print (0+i) for i in range(1, max1+1, 7): if (diadelasemana(1,y,z)+7 == 7): print (0+i) # Programa principal undia=int(input("Ingrese el DIA: ")) unmes=int(input("Ingrese el MES: ")) unaño=int(input("Ingrese el AÑO: ")) validacion = validarfecha(undia,unmes,unaño) if validacion == True: graficar_calendario(undia,unmes,unaño) else: print ("La Fecha ingresada es INVALIDA") # FINI'm stuck and I can't progress... Any help with the restrictions taken into account is much appreciated!