From Scratch to Proficiency β Your Daily Guide to Mastering Python
Welcome to your structured 7-day plan to refresh your Python skills from scratch! Each day focuses on key topics, providing hands-on examples and valuable free resources to guide your learning journey. Let's dive in!
# Calculate area of a circle
radius = float(input("Enter radius: "))
area = 3.14 * radius ** 2
print(f"Area of the circle: {area:.2f}")
# Check if a number is prime
num = int(input("Enter a number: "))
is_prime = True
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
print(f"{num} is {'prime' if is_prime else 'not prime'}.")
# Generate a random password
import random
import string
def generate_password(length=8):
chars = string.ascii_letters + string.digits + "!@#$%"
return ''.join(random.choice(chars) for _ in range(length))
print("Your password:", generate_password(10))
# Count word frequency in a sentence
sentence = "hello world hello python world"
words = sentence.split()
frequency = {}
for word in words:
frequency[word] = frequency.get(word, 0) + 1
print(frequency)
# Read a file and handle exceptions
try:
with open("sample.txt", "r") as file:
content = file.read()
print(content)
except FileNotFoundError:
print("File not found!")
# A simple BankAccount class
class BankAccount:
def __init__(self, balance=0):
self.balance = balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
if amount <= self.balance:
self.balance -= amount
else:
print("Insufficient funds!")
account = BankAccount(100)
account.deposit(50)
account.withdraw(30)
print(f"Balance: ${account.balance}")
tasks = []
while True:
print("\n1. Add Task\n2. View Tasks\n3. Exit")
choice = input("Choose an option: ")
if choice == "1":
task = input("Enter task: ")
tasks.append(task)
elif choice == "2":
print("\nTasks:")
for idx, task in enumerate(tasks, 1):
print(f"{idx}. {task}")
elif choice == "3":
break
else:
print("Invalid choice!")
Happy coding and enjoy your Python journey! π