0% found this document useful (0 votes)
19 views

python project pdf

Uploaded by

susmithareddy959
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

python project pdf

Uploaded by

susmithareddy959
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

import random

# Set the range for the random number


min_num = 1
max_num = 100

# Generate a random number within the range


secret_num = random.randint(min_num, max_num)

# Set the maximum number of attempts


max_attempts = 6

# Initialize the number of attempts


attempts = 0

print("Welcome to Guess the Number!")


print(f"I’m thinking of a number between {min_num} and {max_num}.")
print("You have", max_attempts, "attempts to guess it.")

while attempts < max_attempts:


# Get the player’s guess
user_guess = int(input("Enter your guess: "))

# Check if the guess is correct


if user_guess == secret_num:
print(" Congratulations! You guessed it!")
break

# Provide hints if the guess is too high or too low


elif user_guess > secret_num:
print("Your guess is too high!")
else:
print("Your guess is too low!")

# Increment the number of attempts


attempts += 1

# Display the remaining attempts


print(f"You have {max_attempts - attempts} attempts left.")

if attempts == max_attempts:
print("Sorry, you didn’t guess it. The number was", secret_num)
Welcome to Guess the Number!
I'm thinking of a number between 1 and 100.
You have 6 attempts to guess it.
Enter your guess:
45
Your guess is too low!
You have 5 attempts left.
Enter your guess:
67
Congratulations! You guessed it!

** Process exited - Return Code: 0 **


Press Enter to exit terminal
# task_manager.py

class TaskManager:
def __init__(self):
self.tasks = self.load_tasks()

def load_tasks(self):
try:
with open("tasks.txt", "r") as file:
tasks = [line.strip().split(",") for line in file.readlines()]
return [{"id": int(task[0]), "description": task[1], "complete": task[2] == "True"} for task in tasks]
except FileNotFoundError:
return []

def save_tasks(self):
with open("tasks.txt", "w") as file:
for task in self.tasks:
file.write(f"{task[’id’]},{task[’description’]},{task[’complete’]}\n")

def add_task(self):
description = input("Enter task description: ")
self.tasks.append({"id": len(self.tasks) + 1, "description": description, "complete": False})
self.save_tasks()

def edit_task(self):
task_id = int(input("Enter task ID to edit: "))
for task in self.tasks:
if task["id"] == task_id:
task["description"] = input("Enter new task description: ")
self.save_tasks()
return
print("Task not found!")

def delete_task(self):
task_id = int(input("Enter task ID to delete: "))
self.tasks = [task for task in self.tasks if task["id"] != task_id]
self.save_tasks()

def mark_complete(self):
task_id = int(input("Enter task ID to mark as complete: "))
for task in self.tasks:
if task["id"] == task_id:
task["complete"] = True
self.save_tasks()
return
print("Task not found!")

def display_tasks(self):
for task in self.tasks:
status = "Complete" if task["complete"] else "Incomplete"
print(f"ID: {task[’id’]}, Description: {task[’description’]}, Status: {status}")

def run(self):
while True:
print("Task Manager")
print("1. Add Task")
print("2. Edit Task")
print("3. Delete Task")
print("4. Mark Task as Complete")
print("5. Display Tasks")
print("6. Quit")
choice = input("Enter your choice: ")
if choice == "1":
self.add_task()
elif choice == "2":
self.edit_task()
elif choice == "3":
self.delete_task()
elif choice == "4":
self.mark_complete()
elif choice == "5":
self.display_tasks()
elif choice == "6":
break
else:
print("Invalid choice. Please try again.")

if __name__ == "__main__":
task_manager = TaskManager()
task_manager.run()
Task Manager
1. Add Task
2. Edit Task
3. Delete Task
4. Mark Task as Complete
5. Display Tasks
6. Quit
Enter your choice:
1
Enter task description:
task is palying game
Task Manager
1. Add Task
2. Edit Task
3. Delete Task
4. Mark Task as Complete
5. Display Tasks
6. Quit
Enter your choice:
2
Enter task ID to edit:
3
Task not found!
Task Manager
1. Add Task
2. Edit Task
3. Delete Task
4. Mark Task as Complete
5. Display Tasks
6. Quit
Enter your choice:

Session Killed due to Timeout.


Press Enter to exit terminal
import random

# Predefined list of words


words = ["apple", "banana", "cherry", "date", "elderberry"]

def hangman():
# Select a random word from the list
word = random.choice(words)
word_length = len(word)
guessed_word = ["_"] * word_length
incorrect_guesses = 0
guessed_letters = []

while True:
# Display the current state of the word
print(" ".join(guessed_word))
print(f"Incorrect guesses: {incorrect_guesses}")
print(f"Guessed letters: {’, ’.join(guessed_letters)}")

# Get the player’s guess


guess = input("Enter a letter: ").lower()

# Check if the guess is in the word


if guess in word:
# Fill in the correct letter in the guessed word
for i in range(word_length):
if word[i] == guess:
guessed_word[i] = guess
else:
# Increment the number of incorrect guesses
incorrect_guesses += 1
guessed_letters.append(guess)

# Check for win/loss conditions


if "_" not in guessed_word:
print("Congratulations, you won!")
break
elif incorrect_guesses == 6:
print(f"Game over! The word was {word}.")
break

if __name__ == "__main__":
hangman()
_ _ _ _ _ _
Incorrect guesses: 0
Guessed letters:
Enter a letter:
a
_ _ _ _ _ _
Incorrect guesses: 1
Guessed letters: a
Enter a letter:
d
_ _ _ _ _ _
Incorrect guesses: 2
Guessed letters: a, d
Enter a letter:
n
_ _ _ _ _ _
Incorrect guesses: 3
Guessed letters: a, d, n
Enter a letter:
g
_ _ _ _ _ _
Incorrect guesses: 4
Guessed letters: a, d, n, g
Enter a letter:
j
_ _ _ _ _ _
Incorrect guesses: 5
Guessed letters: a, d, n, g, j
Enter a letter:
g
Game over! The word was cherry.

** Process exited - Return Code: 0 **


Press Enter to exit terminal
import random
import string

def password_generator():
# Define the character sets
letters = string.ascii_letters
numbers = string.digits
symbols = string.punctuation

# Get the password criteria from the user


length = int(input("Enter the desired password length: "))
use_letters = input("Include letters? (yes/no): ").lower() == "yes"
use_numbers = input("Include numbers? (yes/no): ").lower() == "yes"
use_symbols = input("Include symbols? (yes/no): ").lower() == "yes"

# Create the character set based on the user’s criteria


char_set = ""
if use_letters:
char_set += letters
if use_numbers:
char_set += numbers
if use_symbols:
char_set += symbols

# Generate the password


password = "".join(random.choice(char_set) for _ in range(length))

# Print the generated password


print("Generated Password: ", password)

# Ask the user if they want to copy the password to the clipboard
copy_to_clipboard = input("Copy to clipboard? (yes/no): ").lower() == "yes"
if copy_to_clipboard:
print("Password copied to clipboard (note: this is a console-only script, so the password is not
actually copied to the clipboard).")

if __name__ == "__main__":
password_generator()
Enter the desired password length:
5
Include letters? (yes/no):
yes
Include numbers? (yes/no):
yes
Include symbols? (yes/no):
yes
Generated Password: -27t^
Copy to clipboard? (yes/no):
yes
Password copied to clipboard (note: this is a console-only script, so the password
is not actually copied to the clipboard).

** Process exited - Return Code: 0 **


Press Enter to exit terminal

You might also like