Warning
This page is located in archive. Go to the latest version of this course pages.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
courses:pri-bootcamp:solutions [2019/09/09 22:02]
seredlad Suspicious code fixed
courses:pri-bootcamp:solutions [2019/09/19 14:07]
kubikji2
Line 1166: Line 1166:
  
 <code python> <code python>
-Jirka+Kvant
 days = ("​PO",​ "​UT",​ "​ST",​ "​CT",​ "​PA",​ "​SO",​ "​NE"​) days = ("​PO",​ "​UT",​ "​ST",​ "​CT",​ "​PA",​ "​SO",​ "​NE"​)
 months = ("​Leden",​ "​Unor",​ "​Brezen",​ "​Duben",​ "​Kveten",​ "​Cerven",​ "​Cervenec",​ "​Srpen",​ "​Zari",​ "​Rijen","​Listopad","​Prosinec"​) months = ("​Leden",​ "​Unor",​ "​Brezen",​ "​Duben",​ "​Kveten",​ "​Cerven",​ "​Cervenec",​ "​Srpen",​ "​Zari",​ "​Rijen","​Listopad","​Prosinec"​)
 monthsLen = (31,​28,​31,​30,​31,​30,​31,​31,​30,​31,​30,​31) monthsLen = (31,​28,​31,​30,​31,​30,​31,​31,​30,​31,​30,​31)
  
-def printCalendary(year, month, beginDay):+# je rok prestupny?​ 
 +def isleapyear(year): 
 +    # rok je pres 
 +    if (year % 4 == 0 and ((year % 100 != 0) or (year % 400 == 0))): 
 +       ​return 1 
 +    else: 
 +       ​return 0 
  
 +def printCalendary(year,​ month, beginDay):
 + 
    # hlavicka jmeno mesice a rok    # hlavicka jmeno mesice a rok
    ​print(months[month-1],​year)    ​print(months[month-1],​year)
 + 
    # tisknuti zkratek jmen dnu    # tisknuti zkratek jmen dnu
    for i in range(0,7):    for i in range(0,7):
       print(days[i]+"​ ",​end=""​)       print(days[i]+"​ ",​end=""​)
    ​print()    ​print()
 + 
    # tisknuti mezer -- odsazeni 1. dne mesice    # tisknuti mezer -- odsazeni 1. dne mesice
    for i in range(0,​beginDay):​    for i in range(0,​beginDay):​
       print(" ​  ",​end=""​)       print(" ​  ",​end=""​)
 + 
    # tisknuti dnu v mesici    # tisknuti dnu v mesici
    for i in range(1,​monthsLen[month-1]+1):​    for i in range(1,​monthsLen[month-1]+1):​
       print("​%2d " % (i), end=""​)       print("​%2d " % (i), end=""​)
- + 
       # zalomeni u nedele        # zalomeni u nedele
-      if((i+beginDay)%7 == 0): +      if ((i+beginDay)%7 == 0): 
-      print() +         ​print() 
-      ​+ 
 +   # pridatani 29 v pripade, ze je rok prestupny a vypisovany mesic je unor 
 +   if (month == 2 and isleapyear(year) == 1): 
 +      ​print("​29 ", end=""​) 
    ​print()    ​print()
    ​print()    ​print()
 + 
 def countBeginning(year,​ month): def countBeginning(year,​ month):
    # rozdil v rocich od referencniho data    # rozdil v rocich od referencniho data
    dr = year-2018    dr = year-2018
 + 
    # rozdil v dnech na zaklade roku    # rozdil v dnech na zaklade roku
    dd = dr*365 ​    dd = dr*365 ​
 + 
    # rozdil ve dnech na zaklade mesicu    # rozdil ve dnech na zaklade mesicu
    for i in range(0,​month-1):​    for i in range(0,​month-1):​
       dd += monthsLen[i]       dd += monthsLen[i]
  
-   ​dd ​%7+   # reseni dny za prestupne roky 
 +   if year > 2018: 
 +      for y in range(2018,​year):​ 
 +         dd +isleapyear(y)  
 +    
 +   if year < 2018: 
 +      for y in range(year+1,​2018):​ 
 +         dd -= isleapyear(y) ​    
 +    
 +   if isleapyear(year):​ 
 +      dd += 1
  
 +   dd %= 7
 + 
    ​return dd    ​return dd
    
 year = int(input("​Zadejte rok: ")) year = int(input("​Zadejte rok: "))
 month = int(input("​Zadejte mesic: ")) month = int(input("​Zadejte mesic: "))
 + 
 diff = countBeginning(year,​month) diff = countBeginning(year,​month)
 printCalendary(year,​month,​diff) printCalendary(year,​month,​diff)
Line 1618: Line 1642:
  
 <code python> <code python>
-### Proposed by mareddan ### +Jirka 
 def fibonacci(x):​ def fibonacci(x):​
  if x <= 0:  if x <= 0:
Line 1626: Line 1649:
  return 1  return 1
  return fibonacci(x - 1) + fibonacci(x - 2)  return fibonacci(x - 1) + fibonacci(x - 2)
 + 
  
- +number ​int(input("Zadej poradi ve fibonacciho posloupnosti")) 
-if __name__ == "__main__"+result = fibonacci(number) 
- number = 8 +print("​Vysledek je ", result)
- result = fibonacci(number) +
- print(str(number) + "th fibonacci number is:", result)+
 </​code>​ </​code>​
  
courses/pri-bootcamp/solutions.txt · Last modified: 2019/09/19 14:07 by kubikji2