write python code for ideone that makes a hypno-spiral (not really hypnotic, of course!)
- User
write python code for ideone that makes a hypno-spiral (not really hypnotic, of course!)
- Assistant
Here is a simple Python code using the turtle module to create a hypnotic spiral pattern:
import turtle # Set up the turtle screen wn = turtle.Screen() wn.bgcolor("black") # Create turtle called spiral spiral = turtle.Turtle() spiral.speed(0) spiral.width(2) colors = ["red", "blue", "green", "yellow", "orange", "pink", "cyan"] # Draw the spiral for i in range(50): spiral.pencolor(colors[i % len(colors)]) spiral.forward(i * 4) spiral.right(120) wn.mainloop()This code creates a turtle named "spiral" that moves and turns to draw a simple hypnotic spiral pattern using different colors. The turtle's speed and width can be adjusted as needed.
To run the code in an IDE like PyCharm, save it as a .py file and run it. Note that this script won't run on Ideone as it is an online compiler and doesn't support graphical output.
Also, make sure you have the turtle module installed for your Python environment. If you don't have it installed, you can install it with the following command:
pip install PythonTurtleTo make the pattern more hypnotic or complex, you can adjust the angle of rotation and the colors used for the drawing. Happy coding!
- User
write python code for a simple prisoners' dilemma game
- Assistant
Here's a simple Python code for a text-based version of the Prisoner's Dilemma game, where two players (player 1 and player 2) can choose to either cooperate or betray each other. The outcomes are based on common payoff values.
def get_player_choice(player_number): while True: choice = input(f"Player {player_number}, choose cooperate (C) or betray (B): ").upper() if choice in ["C", "B"]: return choice else: print("Invalid input. Please choose C or B.") def evaluate_choices(player1_choice, player2_choice): if player1_choice == "C" and player2_choice == "C": return (3, 3) elif player1_choice == "C" and player2_choice == "B": return (0, 5) elif player1_choice == "B" and player2_choice == "C": return (5, 0) elif player1_choice == "B" and player2_choice == "B": return (1, 1) print("-----Prisoner's Dilemma Game-----") print("Payoffs: (Player 1, Player 2)") print("Both cooperate: (3, 3)") print("Player 1 cooperates, Player 2 betrays: (0, 5)") print("Player 1 betrays, Player 2 cooperates: (5, 0)") print("Both betray: (1, 1)") print("-----------------------------------") player1_choice = get_player_choice(1) player2_choice = get_player_choice(2) result = evaluate_choices(player1_choice, player2_choice) print(f"\nPlayer 1 chose {player1_choice}, Player 2 chose {player2_choice}") print(f"Payoff: (Player 1: {result[0]}, Player 2: {result[1]})")