Statement of Completion#f03c9758
Python Basics
medium
Mastering Python Basics Through Code Debugging
Resolution
Activities
Project.ipynb
Python Basics Capstone¶
1. Data Analysis at DataWars¶
In [ ]:
2. Missing Sale Alert¶
In [1]:
def check_sales(daily_sales):
if daily_sales > 100: # Added colon
return "Good sales day!"
else:
return "Missing target"
3. Bug Hunt: The Missing Projects¶
In [4]:
def add_projects(project1, project2):
total = 0
total = total + project1 # or total += project1
total = total + project2 # or total += project2
return total
# Test the function
result = add_projects(5, 3)
print(f"Total projects: {result}")
Total projects: 8
4. Temperature Tracker¶
In [6]:
def check_temperature(temp):
if temp >= 38: # Added colon
return "Fever! Rest needed"
return "Normal temperature"
5. Fix the Patient Counter¶
In [8]:
def add_patient(total):
total += 1
return total
6. Create Patient Record Variables¶
In [10]:
# Create your variables here
# Create variables for patient information
patient_name = "John Miller"
patient_age = 45
patient_temp = 36.8
has_insurance = True
# Display patient information
print(f"Patient: {patient_name}")
print(f"Age: {patient_age}")
print(f"Temperature: {patient_temp}°C")
print(f"Insurance: {has_insurance}")
Patient: John Miller Age: 45 Temperature: 36.8°C Insurance: True
7. Create Weather App Variables¶
In [12]:
# Create weather variables
location = "New York City"
temperature = 22.5
conditions = "Partly cloudy"
rain_chance = 0.30 # Stored as decimal for percentage
is_daytime = True
# Display dashboard
print("Weather Dashboard:")
print(location)
print(f"Temperature: {temperature:.1f}°C")
print(f"Conditions: {conditions}")
print(f"Rain Chance: {rain_chance:.0%}")
print(f"Daylight: {is_daytime}")
Weather Dashboard: New York City Temperature: 22.5°C Conditions: Partly cloudy Rain Chance: 30% Daylight: True
8. Create E-commerce Product Variables¶
In [19]:
# Create product variables
product_name = 'Gaming Laptop XR-5'
price = 1299.99
free_shipping = True
rating = 4.7
stock = 5
# Display product information
print('Product:', product_name)
print('Price: $'+str(price))
print('Stock:', stock)
print('Free Shipping:', free_shipping)
print('Rating:', rating,'/5')
Product: Gaming Laptop XR-5 Price: $1299.99 Stock: 5 Free Shipping: True Rating: 4.7 /5
9. Create a Doctor's Appointment Function¶
In [23]:
def schedule_appointment(name, time):
if len(name)==0:
return 'Error: Name required'
return f'Appointment confirmed for {name} at {time}'
10. Restaurant Bill Calculator¶
In [31]:
def calculate_bill(meal_cost, tip_percent):
tip_amount = meal_cost * (tip_percent/100)
total = meal_cost + tip_amount
return f"Subtotal: ${meal_cost:.2f}, Total with {tip_percent}% tip: ${total:.2f}"
11. Create a Movie Rating Predictor¶
In [33]:
def predict_rating(length, genre):
if length > 180:
return "Too long, likely 2/5"
elif genre.lower() == "action":
return "Popular! 4/5"
return "Standard 3/5"
12. Create a Social Media Post Analyzer¶
In [35]:
def analyze_engagement(likes, comments, shares):
if likes < 0 or comments < 0 or shares < 0:
return "Invalid input: numbers must be positive"
total = likes + comments + shares
if total > 1000:
return "Viral post!"
return "Normal post"
13. Fix the Playlist Manager¶
In [37]:
def manage_playlist(song, rating):
top_song = ""
if rating > 4.0:
top_song = song
elif rating >= 3.0:
print("Good song!")
else:
print("Skip this one")
return top_song
14. Pizza Order Calculator¶
In [39]:
def calculate_pizza_price(size):
size = size.lower()
if size == "small":
price = 8.99
elif size == "medium":
price = 12.99
elif size == "large":
price = 15.99
else:
return "Error: Choose small, medium, or large only"
return f"{size.capitalize()} pizza: ${price}"
# Test with:
print(calculate_pizza_price("small"))
print(calculate_pizza_price("extra large"))
Small pizza: $8.99 Error: Choose small, medium, or large only
15. Calculate Student Grade¶
In [41]:
def calculate_grade(score):
if score >= 90:
return "A - Excellent!"
elif score >= 80:
return "B - Good job"
elif score >= 70:
return "C - More practice needed"
else:
return "Below C - Schedule tutoring"
16. Coffee Shop Order Validator¶
In [43]:
def validate_coffee_order(size, coffee_type, temperature):
# Convert to lowercase
size = size.lower()
coffee_type = coffee_type.lower()
temperature = temperature.lower()
# Check size
if size != "small" and size != "medium" and size != "large":
return "Invalid size"
# Check coffee type
if coffee_type != "espresso" and coffee_type != "latte" and coffee_type != "cappuccino":
return "Invalid coffee type"
# Check temperature
if temperature != "hot" and temperature != "iced":
return "Invalid temperature"
return "Valid order"
17. Movie Ticket Price Calculator¶
In [45]:
def calculate_ticket_price(age, is_tuesday):
base_price = 12
if age < 12:
price = base_price * 0.5
elif age > 65:
price = base_price * 0.7
else:
price = base_price
if is_tuesday:
price = price - 2
return round(price, 2)
18. Fitness Goal Calculator¶
In [47]:
def calculate_fitness_goal(current_weight, target_weight, weekly_rate):
if weekly_rate < 0.5 or weekly_rate > 1:
return "Weekly rate must be between 0.5-1 kg"
weight_to_lose = current_weight - target_weight
weeks = weight_to_lose / weekly_rate
return round(weeks)
19. Mobile Data Usage Alert¶
In [49]:
def check_data_usage(gb_used, days_left):
limit = 50
remaining = limit - gb_used
daily_average = remaining / days_left
if (gb_used / limit) >= 0.8:
return f"Warning: {remaining}GB left for {days_left} days"
return f"Safe: {daily_average:.1f}GB/day available"
20. Account Login Handler¶
In [ ]:
def validate_login(username, password):
try:
if len(username) < 5:
raise ValueError("Username too short")
if not any(char.isdigit() for char in password):
raise ValueError("Password must contain numbers")
return "Login successful"
except ValueError as e:
return f"Error: {str(e)}"