r/pythonhomeworkhelp • u/[deleted] • Jul 28 '23
r/pythonhomeworkhelp • u/[deleted] • Jul 28 '23
The Ultimate Guide to Python Libraries
r/pythonhomeworkhelp • u/[deleted] • Jul 28 '23
The Best Python IDE for Windows
r/pythonhomeworkhelp • u/[deleted] • Jul 26 '23
Verifying the presence of a value in a list - Python.
r/pythonhomeworkhelp • u/[deleted] • Jul 26 '23
Verifying the presence of a value in a list - Python.
elevatepython.comr/pythonhomeworkhelp • u/[deleted] • Jul 24 '23
The Ultimate Guide To Functions - Python
r/pythonhomeworkhelp • u/[deleted] • Jul 22 '23
An Ultimate Guide to IF Statements - Python
r/pythonhomeworkhelp • u/[deleted] • Jul 20 '23
How to Use the “Pop” Command – Python
r/pythonhomeworkhelp • u/[deleted] • Jul 19 '23
How to Use the “Pop” Command – Python
r/pythonhomeworkhelp • u/[deleted] • Jul 19 '23
ElevatePython - Visit Today >> Learn Python, From Zero to Hero!
r/pythonhomeworkhelp • u/[deleted] • Jul 17 '23
How To Install Scrapy - Windows
r/pythonhomeworkhelp • u/[deleted] • Jul 17 '23
How To Install Scrapy - Windows
r/pythonhomeworkhelp • u/[deleted] • Jul 16 '23
Ultimate Guide To Dictionaries In Python
r/pythonhomeworkhelp • u/[deleted] • Jul 04 '23
If you are new to programming, your first program can become a daunting task! But not for you guys.
If you are new to programming, your first program can become a daunting task! But not for you guys.
I have created a blog post that will help you program your very first Python file! #programming #python #help
Coding Your First Program with Python! – Windows » Elevate Python
r/pythonhomeworkhelp • u/MinhMelt • Apr 04 '23
Beginner python help on code
Hi i was wondering how i have the input "enter your drink" in the same menu with the display drink
class drinks:
def __init__(self,name,cost):
self.name = name
self.cost = cost
#display drink
def __str__(self):
return f"{self.name} : {self.cost} cents"
#select drink
drink = input("Enter drink you would like to purchase: ")
def select_drink(self):
if drink in self.name:
return True
else:
print("This is not one of our drinks")
return False
d1 = drinks("Coffee", 120)
d2 = drinks("Tea", 80)
d3 = drinks("Coke", 150)
d4 = drinks("Juice",100)
print(d1)
print(d2)
print(d3)
print(d4)r/pythonhomeworkhelp • u/josephsark • Mar 08 '23
Buttons disappearing when grid is added
r/pythonhomeworkhelp • u/grendellews • Mar 04 '23
I need help adding a try/except to my code
I am trying to write a code that meets these guidelines:
"Write a function that takes two lists as its parameters and checks if they have the same length. If this is not the case the function should raise a ValueError. If they have the same length the function should create a dictionary, using the first list for keys and the second list for values. The creation of the dictionary should happen in a try except statement, for the case the first list contains mutable types (which should not be used for keys). Finally, the function should return the dictionary."
I wrote this code:
list1 = [1,2,3]
list2 = ["a","b","c", "d"]
list3 = ["x", "y", "z"]
def exer4(a,b):
if len(a) == len(b):
dictionary = dict(zip(a,b))
print(dictionary)
else:
print("nah")
exer4(a= list1, b = list2)
exer4(a= list1, b = list3)But as per the question, I need to make this happen using try/except. When I try to add try somewhere in the problem, calling the function gives me an indent error.
Thank you!
r/pythonhomeworkhelp • u/B_Copeland • Feb 23 '23
Object-Oriented Habit App Homework
Hello everyone,
Based on the following two files, can someone point me in the direction of fixing the error at the bottom of this post.
Interface: from habit import HabitDB, Habit from questionary import prompt, select, text
def create_habit():
name = text("What is the name of the habit?").ask()
frequency = select("What is the frequency of the habit?", choices=["daily", "weekly", "monthly"]).ask()
habit = HabitDB(name, frequency)
habit.save_habit()
def mark_habit_complete():
habits = HabitDB.get_all_habits()
habit_names = [habit.name for habit in habits]
habit_name = select("Which habit do you want to mark as complete?", choices=habit_names).ask()
habit = next(filter(lambda h: h.name == habit_name, habits))
habit.mark_complete()
habit.update()
def delete_habit():
habits = HabitDB.get_all_habits()
habit_names = [habit.name for habit in habits]
habit_name = select("Which habit do you want to delete?", choices=habit_names).ask()
habit = next(filter(lambda h: h.name == habit_name, habits))
habit.delete()
def list_habits():
frequency = select("Which frequency do you want to list habits for?", choices=["daily", "weekly", "monthly"]).ask()
habits = HabitDB.list_by_frequency(frequency)
if not habits:
print(f"No habits found with frequency '{frequency}'")
else:
print(f"Habits with frequency '{frequency}':")
for habit in habits:
print(habit)
def get_streak():
habits = HabitDB.get_all_habits()
habit_names = [habit.name for habit in habits]
habit_name = select("Which habit do you want to get the streak for?", choices=habit_names).ask()
habit = next(filter(lambda h: h.name == habit_name, habits))
streak = habit.get_streak()
print(f"The streak for habit '{habit_name}' is {streak} days")
def help():
print("Commands:")
print("create_habit - create a habit")
print("mark_habit_complete - mark a habit as complete")
print("delete_habit - delete a habit")
print("list_habits - list all habits")
print("get_streak - get the streak for a habit")
print("exit - exit the program")
if __name__ == "__main__":
help()
while True:
command = select("What would you like to do?", choices=["create_habit", "mark_habit_complete", "delete_habit", "list_habits", "get_streak", "exit"]).ask()
if command == "create_habit":
create_habit()
elif command == "mark_habit_complete":
mark_habit_complete()
elif command == "delete_habit":
delete_habit()
elif command == "list_habits":
list_habits()
elif command == "get_streak":
get_streak()
elif command == "exit":
break
else:
print("Invalid command")Habit Class:
import sqlite3
from datetime import datetime, timedelta
class Habit:
def __init__(self, name="", frequency="", completed=[]):
self.name = name
self.frequency = frequency
self.completed = []
def mark_complete(self):
today = datetime.today().date()
self.completed.append(today)
def is_complete(self):
if self.frequency == 'daily':
return datetime.today().date() in self.completed
elif self.frequency == 'weekly':
start_of_week = (datetime.today().date() - timedelta(days=datetime.today().date().weekday()))
end_of_week = start_of_week + timedelta(days=6)
for day in range((end_of_week - start_of_week).days + 1):
date = start_of_week + timedelta(days=day)
if date in self.completed:
return True
return False
elif self.frequency == 'monthly':
today = datetime.today().date()
if today.day >= 28:
end_of_month = today.replace(day=28) + timedelta(days=4)
for day in range((end_of_month - today).days + 1):
date = today + timedelta(days=day)
if date in self.completed:
return True
return False
else:
return today.replace(day=1) in self.completed
def get_streak(self):
streak = 0
today = datetime.today().date()
for day in range((today - timedelta(days=30)).days, (today - timedelta(days=1)).days + 1):
date = today - timedelta(days=day)
if date in self.completed:
streak += 1
else:
break
return streak
class HabitDB:
def __init__(self, name="", frequency="", completed=[]):
self.conn = sqlite3.connect('habits.db')
self.cursor = self.conn.cursor()
self.create_table()
def create_table(self):
self.cursor.execute('''CREATE TABLE IF NOT EXISTS habits
(name TEXT PRIMARY KEY, frequency TEXT, completed TEXT)''')
def save_habit(self, habit):
self.cursor.execute('INSERT INTO habits (name, frequency, completed) VALUES (?, ?, ?)', (habit.name, habit.frequency, str(habit.completed)))
self.conn.commit()
def update_habit(self, habit):
self.cursor.execute('UPDATE habits SET completed = ? WHERE name = ?', (str(habit.completed), habit.name))
self.conn.commit()
def delete_habit(self, habit):
self.cursor.execute('DELETE FROM habits WHERE name = ?', (habit.name,))
self.conn.commit()
def list_habits_by_frequency(self, frequency):
self.cursor.execute('SELECT name FROM habits WHERE frequency = ?', (frequency,))
rows = self.cursor.fetchall()
return [row[0] for row in rows]
def get_all_habits(self):
self.cursor.execute('SELECT * FROM habits')
rows = self.cursor.fetchall()
return rowsTraceback:
Traceback (most recent call last):
File "/home/brandon/IU International University/Object-Oriented and Functional Programing with Python/Habit Tracker v3/main.py", line 57, in <module>
create_habit()
File "/home/brandon/IU International University/Object-Oriented and Functional Programing with Python/Habit Tracker v3/main.py", line 8, in create_habit
habit.save_habit()
TypeError: save_habit() missing 1 required positional argument: 'habit'It states that I am missing a positional argument, however it should have been created when entering all the necessary information into the interface prompts. Any assistance will be greatly appreciated. Thanks in advance!