编辑代码

operation_list = ["create_post", "delete_user", "view_logs"]
pemission_dict = {"Admin":["create_post", "delete_user", "view_logs"], "Editor":["create_post"],"Viewer":["view_logs"]}
user_dict = {"Alice": "Admin", "Bob":"Editor", "Carl":"Viewer"}
temporary_dict = {}

while True:
	command = input("command:")
	if command == "login":
		user = input("Username:")
		if user in user_dict:
			operation = input("Operation: create_post, delete_user, view_logs")
			if operation in operation_list:
				if operation in pemission_dict[user]:
					print("Finished.")
				elif user in temporary_dict and operation == temporary_dict[user]:
					print("Finished.")
                    temporary_dict.pop(user)
                else:
                    print("You're not allowed to do this")
			else:
				print("Illegal operation!!!")
		else:
			print("Illegal username!!!")

	elif command == "change role":
		pw = input("Password:")
		if pw == "123":
			user = input("Username:")
			if user in user_dict:
				role = input("Which role:")
                if role in pemission_dict:
				    user_dict[user] = role
                else:
                    print("Illegal role!!!")
			else:
				print("Illegal username!!!")
		else:
			print("Wrong password!!!")

	elif command == "temporary change":
		pw = input("Password:")
		if pw == "123":
			user = input("Username:")
			if user in user_dict:
				operation = input("Which operation:")
				if operation in operation_list:
					temporary_dict[user] = operation
				else:
					print("Illegal operation!!!")
			else:
				print("Illegal username!!!")
		else:
			print("Wrong password!!!")

    elif command == "exit":
        break
    
    else:
        print("Wrong command. Commands: login, change role, temporary change and exit.")