Guest User

numar.py

a guest
Aug 4th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. import random
  2. import pickle
  3. try:
  4. highscore = pickle.load(open("/sdcard/Download/top10.txt", "rb"))
  5. except IOError:
  6. print("fisierul nu exista")
  7. highscore = []
  8. listaNumere = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  9. amesteca = random.shuffle(listaNumere)
  10. number = random.choice(listaNumere)
  11. #number = random.randint(1, 10)
  12. punctaj = [50, 80, 100]
  13. punctajBonus = [10, 20, 30] # inca nu este bagat
  14.  
  15.  
  16. def ghicireNumar():
  17. vieti = 3
  18. while vieti != 0:
  19.  
  20. ghicire = int(input("Numar norocos: "))
  21. if ghicire == number and vieti == 3:
  22. print("Ai castigat, " + nume + "!! Cu un punctaj de " + str(punctaj[-1]))
  23. highscore.append((nume, punctaj[-1]))
  24. break
  25. elif ghicire == number and vieti == 2:
  26. print("Ai castigat, " + nume + "!! Cu un punctaj de " + str(punctaj[1]))
  27. highscore.append((nume, punctaj[1]))
  28. break
  29. elif ghicire == number and vieti == 1:
  30. print("Ai castigat, " + nume + "!! Cu un punctaj de " + str(punctaj[0]))
  31. highscore.append((nume, punctaj[0]))
  32. break
  33. else:
  34. print("Gresit!! Mai ai " + str(vieti-1) + " incercari")
  35. vieti = vieti -1
  36.  
  37. if vieti == 0:
  38. for item in highscore:
  39. print(str(item) + "\n")
  40.  
  41. def salvareTop():
  42. dumptop = pickle.dump(highscore, open("/sdcard/Download/top10.txt", "wb"))
  43.  
  44.  
  45. def highScore():
  46. print("Top 10")
  47. top = 10
  48. for i in highscore:
  49. print(i)
  50. top -= 1
  51. if top == 0:
  52. break
  53.  
  54. def meniu():
  55.  
  56. alege = int(input("1. Start joc\n2. Top10\n3. Exit\n:"))
  57. if alege == 1:
  58. ghicireNumar()
  59. salvareTop()
  60. elif alege == 2:
  61. highScore()
  62. else:
  63. print ("pa")
  64.  
  65. if __name__ == "__main__":
  66. nume = input("Nickname: ")
  67. print("Salut, " + nume + "!")
  68. meniu()
  69. # Mai trebuie:
  70. # -salvarea top-ului si incarcarea lui la fiecare rulare
  71. # -punctajul bonus
Add Comment
Please, Sign In to add comment