FreeCodeCamp » Python
2,293 FOLLOWERS
Ask questions and share tips related to Python or any tools in the Python ecosystem, and get the best python tutorials and solutions here. FreeCodeCamp is a developer community where you can learn to code for free.
FreeCodeCamp » Python
17m ago
Tell us what’s happening:
The hint says i should pass the map function as the argument in the sum function.
My code does the exact thing but still can’t pass, why?
Your code so far
def add_expense(expenses, amount, category):
expenses.append({'amount': amount, 'category': category})
def print_expenses(expenses):
for expense in expenses:
print(f'Amount: {expense["amount"]}, Category: {expense["category"]}')
# User Editable Region
def total_expenses(expenses):
sum(map(lambda expense: expense['amount'],expenses))
# User Editable Region
expenses = []
Your ..read more
FreeCodeCamp » Python
4h ago
Tell us what’s happening:
i wrote the message and the offset in , but it didnt helps me
Your code so far
text = 'Hello Zaira'
shift = 3
def caesar(message, offset):
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text = ''
for char in message.lower():
if char == ' ':
encrypted_text += char
else:
index = alphabet.find(char)
new_index = (index + offset) % len(alphabet)
encrypted_text += alphabet[new_index]
print('plain text:', message)
# User Editable Region
print('encrypted text:', encrypted_text)
caesar ..read more
FreeCodeCamp » Python
5h ago
Hi, I’m having trouble getting my code to pass:
text = ‘Hello Zaira’
custom_key = ‘python’
def vigenere(message, key, direction):
key_index = 0
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
encrypted_text = ‘’
for char in message.lower():
# Append space to the message
if char == ' ':
encrypted_text += char
else:
# Find the right key character to encode
key_char = key[key_index % len(key)]
key_index += 1
# Define the offset and the encrypted letter
offset = alphabet.index(key_char)
index = alphabet.find(char)
new_i ..read more
FreeCodeCamp » Python
13h ago
Tell us what’s happening:
I have been trying to work through this question “Now, instead of printing ‘space!’, use the addition assignment operator to add the space (currently stored in char) to the current value of encrypted_text.”
But I am just not sure as to how to advance with this question. I have tried if char+= encrypted_text: with no print() in there and it told me I was getting close. The encrypted_text is already set to ’ ’ but it is saying the space is added in char. Thank you!
Your code so far
# User Editable Region
text = 'Hello World'
shift = 3
alphabet = 'abcdefghijklmnopqrstu ..read more
FreeCodeCamp » Python
13h ago
Hello active learners !
I’m stuck at the very last test of the Python Budge App project that tests the “create_spend_chart”. Here’s what I did:
counted the number of characters of the output chart
compared it against the example given in the project description
doubled checked that each bar should show the “rounded down” (14.9 should be considered as 20, where as 14.0 should be 10) version of percentage of “total expenses of a category over total deposit”
Could anyone please help ?
class Category:
def __init__(self, name):
self.name = name
self.ledger = [] #must be an instance inste ..read more
FreeCodeCamp » Python
17h ago
Tell us what’s happening:
Hello, all. I was having an issue where I was having extra spaces at the end of my last problem and that was causing the tests to not be correct. So in order to fix this, I decided to use a for loop to iterate over the last element to strip the last spaces on each line, but for some reason, it won’t work. If someone is able to help me, or understands why this is happening and would be able to explain it to me and possibly help me fix, that would be appreciated
Your code so far
def arithmetic_arranger(problems, show_answers=False):
line1 = ''
line2 = ''
li ..read more
FreeCodeCamp » Python
18h ago
Tell us what’s happening:
Hello @team, I’m struggling and stressing you over this, please help me with that
Your code so far
my_graph = {
'A': [('B', 3), ('D', 1)],
'B': [('A', 3), ('C', 4)],
'C': [('B', 4), ('D', 7)],
'D': [('A', 1), ('C', 7)]
}
# User Editable Region
def shortest_path(graph, start):
unvisited = []
for i in graph:
unvisited.append('A','B','C','D')
# User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (iPhone; CPU iPhone OS 15_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/120.0.6099.119 Mobile/15E14 ..read more
FreeCodeCamp » Python
23h ago
Tell us what’s happening:
I have changed the indentation, but still not working
Your code so far
def square_root_bisection(square_target, tolerance=1e-7, max_iterations=100):
if square_target < 0:
raise ValueError('Square root of negative number is not defined in real numbers')
if square_target == 1:
root = 1
print(f'The square root of {square_target} is 1')
elif square_target == 0:
root = 0
print(f'The square root of {square_target} is 0')
else:
low = 0
high = max(1, square_target)
root = None ..read more
FreeCodeCamp » Python
1d ago
Tell us what’s happening:
You should create an if statement that checks if root is None.
Your code so far
def square_root_bisection(square_target, tolerance=1e-7, max_iterations=100):
if square_target < 0:
raise ValueError('Square root of negative number is not defined in real numbers')
if square_target == 1:
root = 1
print(f'The square root of {square_target} is 1')
elif square_target == 0:
root = 0
print(f'The square root of {square_target} is 0')
else:
low = 0
high = max(1, square_target)
root = None ..read more
FreeCodeCamp » Python
1d ago
Tell us what’s happening:
So here is my problem
I have to define a new custom function for my caesar cipher
when I write def caesar_name(): It tells me I need to add to parenthesis
I redo do it, and then it tells me I need to add an indentation after shift = 3
I do that
The terminal says its an unnecessary indentation
I remove it
Now its telling me to add the def term that’s already there
So can someone explain to me whats going on?
Your code so far
# User Editable Region
text = 'Hello Zaira'
shift = 3
def caesar_function():
code
alphabet = 'abcdefghijklmnopqrstuvwxyz'
encrypted_text ..read more