+ 1

Python Control Flow Task Question

Hi, I’ve been stuck at the task “Going once, going twice, sold!” Task for a while now and I can’t seem to find what’s exactly wrong with my code. My code looks like this: maxBid = int(input()) while(True): bid = int(input)) if bid > maxBid: break print(“Sold:” , bid) Thanks in advance!!

29th Mar 2023, 7:04 AM
Eleni D
Eleni D - avatar
11 Antworten
+ 4
Now your print statement is inside loop. But should be after loop like in your original previous code.
29th Mar 2023, 8:45 AM
Jayakrishna 🇼🇳
+ 7
Eleni D , just some words about the code formatting. > styleguide for python code is described in pep-0008. > indentation should be 4 spaces per indentation level. this has a much better readability than using only one space. this the link to the style guide: https://peps.python.org/pep-0008/#indentation
29th Mar 2023, 11:39 AM
Lothar
Lothar - avatar
+ 3
What's the task? Normally, with these tasks, you really have to pay attention to how the output should look like. Do you have the right amount of space etc?
29th Mar 2023, 7:47 AM
Ausgrindtube
Ausgrindtube - avatar
+ 3
You are missing the () for the input() function in loop. And you are using the wrong quotes for string. Use double quotes "Sold:"
29th Mar 2023, 8:33 AM
Jayakrishna 🇼🇳
+ 3
Ok, so there are possibly a few things wrong. 1st: bid = int(input()) #you're missing a ( 2nd: if bid >= maxBid: #the maximum bid is met if the bid is the same amount or greater 3rd: print("Sold:", bid) #I don't know if you're using quotation marks or 2x backticks
29th Mar 2023, 8:38 AM
Ausgrindtube
Ausgrindtube - avatar
+ 3
You are a genius! Crazy how much the little details matter! Thanks to both you
29th Mar 2023, 8:47 AM
Eleni D
Eleni D - avatar
+ 2
Task: You are writing a program for an auction where the maximum bid is set. The number of bids is variable. Task Complete the program to take all bids from auction participants until the maximum bid is met. The program should output a message with the winning bid. Input Example 1600 800 1300 1700 Output Example Sold: 1700 Explanation The first input represents the set maximum bid, followed by the bids offered by all participants. The last participant offered a bid of 1700, which is above the maximum set bid of 1600, and therefore wins the auction. Therefore, that bid is displayed.
29th Mar 2023, 7:49 AM
Eleni D
Eleni D - avatar
+ 1
Updated the code but it's still not working maxBid = int(input()) while(True): bid = int(input()) if bid >= maxBid: break print("Sold", bid)
29th Mar 2023, 8:41 AM
Eleni D
Eleni D - avatar
+ 1
print(f"Sold: {bid}") Try this if it works good its ok But if not ask for chatgpt And try to edit this also if bid == 'maxBid':
29th Mar 2023, 5:52 PM
Jehan32
Jehan32 - avatar
+ 1
Mohammad Mondgar please don't try to hijack another person's thread. If you have a question, search the forum first, do some research online and then, if you still don't have your answer, ask and provide some code which needs help. Furthermore, malicious hacking is not a very moral or ethical thing to do. Couldn't you put your energy into something more beneficial for the rest of your world?
31st Mar 2023, 6:21 AM
Ausgrindtube
Ausgrindtube - avatar
0
Hi! I want to know all hackers code but send for me please🙏🙏
31st Mar 2023, 12:10 AM
Mohammad Mondgar
Mohammad Mondgar - avatar