#๐Ÿ”’ Error

125 messages ยท Page 1 of 1 (latest)

lusty pulsar
#

Can someone please help me with this code?

edgy kilnBOT
#

@lusty pulsar

Python help channel opened

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.

tulip loom
#

looks like you never defined items

lusty pulsar
#

i tried to change it to max

#

but the name of the bidder doest correspond to the max biud

#

bid

jaunty fossil
#

you have put while other_bidders=='Yes'

so if you put No as answer the loop doesnt get executed

lusty pulsar
#

what

#

dont i have it there?

jaunty fossil
lusty pulsar
#

i dont think so

#

or do i

jaunty fossil
#

I think you do

lusty pulsar
#

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

jaunty fossil
#

!paste

edgy kilnBOT
#
Pasting large amounts of code

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.

jaunty fossil
#

can you send the entire code

lusty pulsar
#

art is just another modul

jaunty fossil
#
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
lusty pulsar
#

hold on, lemme process it first

#

๐Ÿ’€

jaunty fossil
#

its exactly what you are doing except it is broken down into more steps

lusty pulsar
#

so the max function was wrong?

jaunty fossil
#
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

lusty pulsar
#

i thought that if i use that it will automatically like input the pair of highest value and its key

jaunty fossil
#

max(names_of_the_bidders) and max(bids_of_the_bidders) indivisually

jaunty fossil
lusty pulsar
#

crap, good to know

jaunty fossil
#

it ends up comparing the ascii value of the string and an integer

lusty pulsar
#

lemme try that again

jaunty fossil
#

keep that in mind

lusty pulsar
#

so that would mean that i dont need the variable highest_bid_and_bidder

jaunty fossil
#

it wont give the highest bidder

lusty pulsar
#

bruh

jaunty fossil
jaunty fossil
#

d[name]=bid

#

and then do

#
for name in d:
   #find out max d[name]
lusty pulsar
#

ah yeah

#

for loop

#

god i hate loops

#

they never cross my mind

jaunty fossil
#

haha okay wait lemme think of something without loop

lusty pulsar
#

nah it's ok

jaunty fossil
#

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]]

lusty pulsar
#

why do i see wiener all the time

#

smh

jaunty fossil
#

๐Ÿ’€

edgy kilnBOT
#

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.
lusty pulsar
#

ah, crap

jaunty fossil
#

idk the details tho

#

let me know if you face any problem in understanding

#

I will try to explain

lusty pulsar
#

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

wet rampart
#

he gotta learn to use them too

lusty pulsar
#

i agree

jaunty fossil
wet rampart
#

bro allat is more complex than using loops

lusty pulsar
#

i guess

lusty pulsar
#

i think your bidders is mine add_bidder

jaunty fossil
#

mine is like this

#

because you need to pair the names and bids together
so that printing is eaasier

lusty pulsar
lusty pulsar
jaunty fossil
lusty pulsar
#

ahh

jaunty fossil
#

let me know if you want to understand how to find the max using 2 lists and their index as the common connector

wet rampart
#

is he using 2 lists as a dictionary essentially?

#

with corresponding indexes?

jaunty fossil
#

well he tried to.. but used max() on a string list which caused problems

wet rampart
#

lol

#

does it only have strings?

jaunty fossil
#

nah I think he understood the problem

lusty pulsar
#

key is string value is integer

wet rampart
#

huh

jaunty fossil
wet rampart
#

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

jaunty fossil
#

I dont think you understand the problem

wet rampart
#

no i don't

lusty pulsar
#

well the code seems to be working now

wet rampart
#

bro didn't send the full code

#

w

jaunty fossil
lusty pulsar
#

i'll just try to understand it more

jaunty fossil
lusty pulsar
#

smh i' ve been coding for quite some time now

#

but

#

what does break do

jaunty fossil
#

break force stops a loop

#

so for eg

for name in names:
  if name==search:
      #put logic here
      break
lusty pulsar
#

so with break we dont need to write if the loop is becomes wrong

jaunty fossil
#

so break instantly breaks the loop and saves processing power

jaunty fossil
#

you dont write break

lusty pulsar
#

got it

#

i think i've grasped everything now

#

thank you for your assistance

jaunty fossil
#

๐Ÿ‘ anytime

edgy kilnBOT
#
Python help channel closed

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.