Advertisement
Guest User

Untitled

a guest
Feb 28th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.27 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. import sys
  3. import copy
  4. import os
  5. goods = {
  6. 'apple': 10,
  7. 'tesla': 100000,
  8. 'macbook': 3000,
  9. 'bike': 200,
  10. }
  11. with open('registers.txt', 'a+') as reg, open('blacklist.txt', 'a+') as black, \
  12. open('new_reg.txt','w') as newreg:
  13. reg.seek(0)
  14. line = reg.readline()
  15. flag = True
  16. while flag:
  17. flag = False
  18. move = input('register or login:').strip().lower()
  19. if move == 'register':
  20. reg.read()
  21. user = input('input your name:')
  22. exit_user = []
  23. reg.seek(0)
  24. line = reg.readline()
  25. while line:
  26. line = line.strip().split('|')
  27. exit_user.append(line[0])
  28. line = reg.readline()
  29. if user in exit_user:
  30. print('you name is already registered,login directly')
  31. flag = True
  32. continue
  33. else:
  34. pswd = input('input your password :')
  35. account = input('input your money :')
  36. pswd2 = input('input your password again:')
  37. while pswd != pswd2:
  38. pswd2 = input('wrong password!input again:')
  39. reg.write(user+'|'+pswd+'|'+account+'\n')
  40. flag = True
  41. print('register success,login please')
  42. continue
  43. elif move == 'login':
  44. user = input('input your name:')
  45. black.seek(0)
  46. blackusers = black.readline().split()
  47. if user not in blackusers:
  48. pswd = input('input your password :')
  49. else:
  50. print('you are in the blacklist now')
  51. sys.exit()
  52.  
  53. exit_flag = False
  54. reg.seek(0)
  55. line = reg.readline()
  56. while line:
  57. line = line.strip().split('|')
  58. if user == line[0]:
  59. for i in range(2):
  60. if pswd == line[1]:
  61. exit_flag = True
  62. break
  63. else:
  64. pswd = input('wrong password!input again:').strip().lower()
  65. if exit_flag:
  66. break
  67. print('you have inputted the password for three times,'
  68. 'welcome to the blacklist')
  69. black.read()
  70. black.write(user + ' ')
  71. #sys.exit()
  72. flag = True
  73. break
  74. else:
  75. line = reg.readline()
  76. if not exit_flag :
  77. print('you have not registered ,register please')
  78. flag = True
  79. else:
  80. print('wrong command!input again:').strip().lower()
  81. flag = True
  82.  
  83. print('\nthe goods you can buy and their prices are as follows:\n' + str(goods))
  84. #buys = goods 强调用
  85. buys = copy.deepcopy(goods)
  86. for key in buys.keys():
  87. buys[key] = 0
  88.  
  89. while True:
  90. thing = input('input the one you want: ').strip().lower()
  91. if thing not in buys.keys():
  92. print('wrong name,input again:')
  93. continue
  94. num = int(input('input the number you want to buy: ').strip().lower())
  95. cost = num*goods[thing]
  96. if cost > int(line[2]):
  97. print('your money left is not enough:'+ line[2])
  98. answer = input('do you want to continue?y or n:').strip().lower()
  99. if answer == 'n':
  100. break
  101. else:
  102. continue
  103. else:
  104. line[2] = str(int(line[2]) - cost)
  105. buys[thing] = buys[thing] + num
  106. print('your money left is:' + line[2])
  107. answer = input('do you want to continue?y or n:').strip().lower()
  108. if answer == 'n':
  109. break
  110. else:
  111. continue
  112. print('the things you buy and the number are:\n' + str(buys)+'\n')
  113. print('your money left is ' + line[2])
  114.  
  115. reg.seek(0)
  116. newreg.seek(0)
  117. for everyline in reg:
  118. newline = everyline.strip().split('|')
  119. if newline[0] == line[0]:
  120. newreg.write(line[0] + '|' + line[1] + '|'+ line[2]+'\n')
  121. else:
  122. newreg.write(everyline)
  123. os.remove('registers.txt')
  124. os.rename('new_reg.txt','registers.txt')
  125.  
  126. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement