#๐ Error
125 messages ยท Page 1 of 1 (latest)
@lusty pulsar
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
looks like you never defined items
i tried to change it to max
but the name of the bidder doest correspond to the max biud
bid
you have put while other_bidders=='Yes'
so if you put No as answer the loop doesnt get executed
you have the 'no' condition inside the loop right
I think you do
but i dont think that seems to be the problem
cause when i run it
it does print the highest value in the dictionary
but wrong key
it always prints the first key and the highest value
this is the code
!paste
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
can you send the entire code
if other_bidders == "No":
clear()
winner_name, highest_bid = find_winner(bidders)
print(f"The winner is {winner_name} with a bid of ${highest_bid}")
break
and then
def find_winner(bidders):
highest_bid = 0
winner = ""
for bidder in bidders:
if bidder[1] > highest_bid:
highest_bid = bidder[1]
winner = bidder[0]
return winner, highest_bid
its exactly what you are doing except it is broken down into more steps
so the max function was wrong?
if other_bidders == "No":
highest_bid_and_bidder = max(names_of_the_bidders,bids_of_the_bidders)
print(f"The winner is {max(names_of_the_bidders)} with the bid of {max(bids_of_the_bidders)}")
max function finds out the maximum value from name_of_the_bidders and bids_of_the_bidders
which is logically flawed
you can do
i thought that if i use that it will automatically like input the pair of highest value and its key
max(names_of_the_bidders) and max(bids_of_the_bidders) indivisually
yes max doesnt work like that
crap, good to know
it ends up comparing the ascii value of the string and an integer
ah i think i had it at one time
lemme try that again
max(names_of_the_bidders) will compare according to ascii value
keep that in mind
so that would mean that i dont need the variable highest_bid_and_bidder
it wont give the highest bidder
bruh
you can manually iterate through the list like I've done and store it there
or you can put the bid and bidders in a dictionary
d[name]=bid
and then do
for name in d:
#find out max d[name]
haha okay wait lemme think of something without loop
nah it's ok
I think you can do
like
master=[]
#get name and bid
master.append([name,bid])
winner=max(master,key=lambda: x:x[1])
winner_name=winner[0]
winner_bid=winner[1]
basically
master is in this format
master = [["Alice", 100], ["Bob", 150], ["Charlie", 120]]
๐
Hey @lusty pulsar!
It looks like you're trying to paste code into this channel.
Discord has support for Markdown, which allows you to post code with full syntax highlighting. Please use these whenever you paste code, as this helps improve the legibility and makes it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
ah, crap
idk the details tho
let me know if you face any problem in understanding
I will try to explain
right, lemme get on
with it
why is bidder[1] and not without the 1
[1] this means the first bidder in the dictionary right
bro use loops, they're the most broken thing in python
he gotta learn to use them too
i agree
bidder is also a nested iterable
so bidder[1] has the bid
and bidder[0] has the name
bro allat is more complex than using loops
i guess
then that means bidder does not exist cause i dont see it anywere
i think your bidders is mine add_bidder
bidders = []
def add_bidder(name, bid):
bidders.append((name, float(bid)))
mine is like this
because you need to pair the names and bids together
so that printing is eaasier
that is the same as mine lol
here
yes but in the same iterable
otherwise you need to find the max bid's index
ahh
let me know if you want to understand how to find the max using 2 lists and their index as the common connector
well he tried to.. but used max() on a string list which caused problems
nah I think he understood the problem
key is string value is integer
huh
even in a string list
the index is integer
bro if there are numbers in the same list he can just do
temp = []
for item in values:
if type(item) == int:
temp.append(item)
print(max(temp))
or are there no numbers in the list
I dont think you understand the problem
no i don't
well the code seems to be working now
great, make sure you understand everything
i'll just try to understand it more
ok let me know if you have any doubts
break force stops a loop
so for eg
for name in names:
if name==search:
#put logic here
break
so with break we dont need to write if the loop is becomes wrong
so break instantly breaks the loop and saves processing power
if the loop isnt running
you dont write break
๐ anytime
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.