I need to write a program that prompts the user to enter numbers, and stores/displays the largest & smallest integer entered.
However, I can only do this with simple data types (no arrays.)
This is what I have so far.
def main()
while number != -99:
number = input('Enter a number: ')
compare = input('Please enter another number: ')
if compare < number then
compare = smallest
I'm sorry it's just a mess. We're not actually taught python in this class, only psuedo-code then just kind of sent on our own to figure it out.
If you don't need to keep all the numbers, then simply keep two variables maximum and minimum in two variables and only assign the latest user data entry to one or the other depending on whether it is lesser / greater or not - plus a special case to get the first number started in both variables. Here is a little pseudo-code example...
Maximum = NULL
Minimum = NULL
Do
Get User Input string
If Input is Blank Then Exit Loop
Input = Convert Input to Number
If Maximum=NULL
Then Maximum=Input
Else If Input > Maximum Then Input = Maximum
If Minimum=NULL
Then Minimum=Input
Else If Input < Minimum Then Input = Minimum
Loop
Print "Min = " + Minimum
Print "Max = " + Maximum
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.