Advertisement
mbwlodarczyk

wyświetlanie, nawigacja, mastermind, rekurencja

Jun 18th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.99 KB | None | 0 0
  1. #funkcja wyświetlająca
  2. def printMenu():
  3.   """Funkcja wypisująca menu użytkownika"""
  4.   print("--------------")
  5.   print("--- Menu ---")
  6.   print("--------------")
  7.  
  8.  
  9.  
  10. #nawigacja
  11. def navigation(choice):
  12.   """Funkcja obsługująca wybór"""
  13.   choice = choice.lower()
  14.  
  15.  
  16.  
  17. #mastermind
  18. #funkcja realizująca grę mastermind
  19.  
  20. import random
  21.  
  22. n1 = random.randint (1,9)
  23. n2 = random.randint (1,9)
  24. n3 = random.randint (1,9)
  25. n4 = random.randint (1,9)
  26. numberswrong = 0
  27. print (n1,n2,n3,n4)
  28. guess1 = input("Podaj pierwszą liczbę: ")
  29. guess2 = input("Podaj pierwszą liczbę: ")
  30. guess3 = input("Podaj pierwszą liczbę: ")
  31. guess4 = input("Podaj pierwszą liczbę: ")
  32. guess1 = int (guess1)
  33. guess2 = int (guess2)
  34. guess3 = int (guess3)
  35. guess4 = int (guess4)
  36. if guess1 != n1:
  37.     numberswrong +=1
  38. else:
  39.     numberswrong +=0
  40. if guess2 != n2:
  41.     numberswrong +=1
  42. else:
  43.     numberswrong +=0
  44. if guess3 != n3:
  45.     numberswrong += 1
  46. else:
  47.     numberswrong += 0
  48. if guess4 != n4:
  49.     numberswrong += 1
  50. else:
  51.     numberswrong += 0
  52. print("Masz", numberswrong, "błędów")
  53. if numberswrong == 0:
  54.     print("Well done")
  55. while numberswrong != 0:
  56.     guess1 = input("Podaj pierwszą liczbę: ")
  57.     guess2 = input("Podaj pierwszą liczbę: ")
  58.     guess3 = input("Podaj pierwszą liczbę: ")
  59.     guess4 = input("Podaj pierwszą liczbę: ")
  60.     guess1 = int(guess1)
  61.     guess2 = int(guess2)
  62.     guess3 = int(guess3)
  63.     guess4 = int(guess4)
  64.     if guess1 != n1:
  65.         numberswrong += 1
  66.     else:
  67.         numberswrong += 0
  68.     if guess2 != n2:
  69.         numberswrong += 1
  70.     else:
  71.         numberswrong += 0
  72.     if guess3 != n3:
  73.         numberswrong += 1
  74.     else:
  75.         numberswrong += 0
  76.     if guess4 != n4:
  77.         numberswrong += 1
  78.     else:
  79.         numberswrong += 0
  80.     print("Masz", numberswrong, "błędów.")
  81. print("Dobra robota")
  82.  
  83.  
  84.  
  85. #rekurencja
  86. def funk(x):
  87.     if x < 10:
  88.         print(x)
  89.         return funk(x + 1)
  90.     else:
  91.         return 0
  92.  
  93.  
  94. print(funk(2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement