To-Do task list

tasks = {}

def add_task(task):
    tasks[task] = False

def complete_task(task):
    tasks[task] = True

def list_tasks():
    for task, completed in tasks.items():
        print(f"{task}: {completed}")

while True:
    action = input("What would you like to do? ")
    if action == "add":
        task = input("Enter the task to add: ")
        add_task(task)
    elif action == "complete":
        task = input("Enter the task to complete: ")
        complete_task(task)
    elif action == "list":
        list_tasks()
    elif action == "quit":
        break
    else:
        print("Invalid action")

print(tasks)
{'eat': False, 'lunch': True}

This code is a simple task management program that allows the user to add tasks, mark tasks as complete, and list all the tasks.

The program begins by defining an empty dictionary called tasks. The dictionary will store the tasks as keys and a boolean value indicating whether the task has been completed or not.

The program then defines three functions:

add_task: This function adds a task to the dictionary with a value of False (indicating it has not been completed yet). complete_task: This function sets the value of a given task to True (indicating it has been completed). list_tasks: This function iterates through the tasks in the dictionary and prints the task name and its completion status. The program then enters a while loop that prompts the user for an action (either "add", "complete", "list", or "quit"). If the action is "add", the program prompts the user for a task and adds it to the dictionary using the add_task function. If the action is "complete", the program prompts the user for a task and marks it as complete using the complete_task function. If the action is "list", the program lists all the tasks using the list_tasks function. If the action is "quit", the program breaks out of the while loop and ends. If the user enters an invalid action, the program prints an error message.

Finally, after the while loop ends, the program prints the dictionary of tasks.

Rock Paper Scissors game

import random

choices = ["rock", "paper", "scissors"]

def play_game():
    # Get the user's choice
    user_choice = input("Enter your choice (rock/paper/scissors): ")
    # Get the computer's choice
    computer_choice = random.choice(choices)
    # Determine the winner
    if user_choice == computer_choice:
        result = "Tie"
    elif user_choice == "rock" and computer_choice == "scissors":
        result = "You win!"
    elif user_choice == "paper" and computer_choice == "rock":
        result = "You win!"
    elif user_choice == "scissors" and computer_choice == "paper":
        result = "You win!"
    else:
        result = "Computer wins"
    # Print the results
    print(f"You chose {user_choice} and the computer chose {computer_choice}")
    print(result)

# Play the game
play_game()
You chose paper and the computer chose rock
You win!

This code is a simple Rock-Paper-Scissors game that allows the user to play against the computer.

The program begins by importing the random module and defining a list of choices. It then defines the play_game function, which prompts the user for their choice and generates a random choice for the computer using the random.choice function.

The program then determines the winner of the game by comparing the user's choice and the computer's choice. If the user's choice is the same as the computer's choice, it's a tie. Otherwise, it checks if the user's choice wins against the computer's choice using a series of if statements. If none of the conditions are met, the result is "Computer wins".

The program then prints the results of the game, including the user's choice and the computer's choice.

To play the game, you can run this code in a Python interpreter or save it to a file and run it with python filename.py. The program will prompt you to enter your choice, and then print the results of the game.

This is a simple mad libs game

def mad_libs():
    noun = input("Enter a noun: ")
    verb = input("Enter a verb: ")
    adjective = input("Enter an adjective: ")
    adverb = input("Enter an adverb: ")

    print(f"The {adjective} {noun} likes to {verb} {adverb}.")

mad_libs()
The fast saavan likes to run a lot.

This code is a simple Mad Libs program that prompts the user for a noun, verb, adjective, and adverb, and then uses those words to create and print a sentence.

The program begins by defining the mad_libs function, which prompts the user for a noun, verb, adjective, and adverb and stores them in variables. It then uses these variables to create a sentence using string formatting, and prints the sentence to the screen.

To play Mad Libs, you can run this code in a Python interpreter or save it to a file and run it with python filename.py. The program will prompt you to enter the words, and then print the generated sentence. You can customize the program by adding more prompts for different parts of speech and incorporating them into the sentence. You can also add more sentences or create a function to generate multiple Mad Libs sentences. Let me know if you have any specific questions about how to customize the program!