largest = None
smallest = None
while True:
num = input("Enter a number: ")
if num == "done" : break
print(num)
print("Maximum", largest)
The above is the hint code. When you output Done, you repeatedly process the example numbers to output the maximum and minimum values, and the other values are wrong and the input is returned to continue... My code keeps getting twisted and it's getting an error.
largest = None
smallest = None
numbers = [7, 2,'bob', 10, 4]
while True :
num = input('Enter a number: ')
if num == 'done' : break
for num > numbers :
print(num)
else num =! numbers
print("It's wrong number")
print(largest, smallest)
continue
print('Invalid input')
print('Maximum is ' largest)
print('Minimum is ' smallest)
It's the code I'm writing. I don't think it should be this long, but it seems to be longer, and there is an infinite loop that cannot end the repetition in the break part. Even though it's a basic lecture, it's depressing to take this long for a assignment... I wanted to solve it by myself somehow, but I've been shoveling for two days, so I think it'll be very helpful if you give me some advice.
python if문
1) The code you wrote seems to be roughly this idea (to ignore, although there are many grammatical errors).
Will it work if we just follow this idea? I'm not going to do it. Lack of ideas (exactly 'procedures') The requirements given seem simple, but much more procedures should be given in the order in which we (or computers) perform those requirements. It's helpful to think about what you'll do if you ask me to handle this.
2) So let's think about the procedure. If,
The professor suddenly called up the questioner while passing by.
"From now on, I'll call you some numbers or text messages until I say I'm done. Listen carefully and let me know the maximum and minimum values."
Then what do we usually do at times like this?
In this scenario, we've actually laid out the procedures for performing these tasks in the order of (1) and (2) without logical exceptions (3) only necessary things. (This is called 'Six Order', or 'Program') Is there any problem if I follow this procedure and do what the professor told me to do? There won't be any problems anyway, so if you just translate it into the computer's language and teach it to the computer, wouldn't it be handled without any problems even if the computer replaced it? This is called programming.)
3) The following is a pseudo-code written for reference because the questioner seems to be violating the basic grammar of Python a lot. Please try it yourself from here. (Because I haven't tested it.)
Maximum = (I don't know)
Minimum = (I don't know)
The numbers so far = (empty list)
Unconditionally repeat:
Input value = Receive input
If input value == 'Done':
Stop it again and stop it
Or:
Try: # This is the 'try' part.
In Input Value = Number Replacement Input Value # Python, the phrase 'non-int' will be ruined.
Input value to add to the numbers that have come out so far
If you fail while trying: # 'exception' part.
"That's not a number. Please sing it again"
If the number of numbers so far == 0:
Arguing. "You didn't call me any numbers. Please do it again"
Or:
Let's say x each of the numbers that have come out so far and look at it: # 'for' repeat. Python is abbreviated like this because there is a for abbreviated grammar that goes around the entire list.
If x > Maximum:
Maximum = x
If x < Minimum:
Minimum = x
Tell me "The largest number" is "Maximum"
Tell me "The smallest number is the "minimum" Then I'll go now
Finally, you were curious about the length of the cord... If you're just talking about length, you can use the next algorithm to do it in a shorter code. The assignment itself seems to be more intended. In this scenario, there will be a difference in program performance because you have to use fewer notes (memory) but you have to make a lot of judgments (computations) every time.
© 2024 OneMinuteCode. All rights reserved.