0

OK I just did an assignment ( self learning) now I need to do another but want to convert current code but cant see how. :(

Current code: n = 0 count = 0 user = input('Enter Numbers:\n> ') while user != 'done': try: n = n + float(user) count = count + 1 except: print('Enter Numbers or "done"') user = input('> ') avg = n/count if user == 'done': print('Total:',n) print('Count:',count) print('Average:',avg) now I need to convert my previous code to this question. I have tried many different ideas ( just a beginner ) but not working. any idea? "Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below."

18th Oct 2017, 4:54 PM
Aric Dunn
Aric Dunn - avatar
8 odpowiedzi
+ 2
https://code.sololearn.com/cD4EwOPgX4fn/?ref=app simple problem :) I have used one list 'A' to store every entered values then found maximum and minimum value by inbuilt attributes.
18th Oct 2017, 5:06 PM
Prajwal Gowda
Prajwal Gowda - avatar
+ 2
I am also learner. You can find append usage in this app only.
18th Oct 2017, 5:13 PM
Prajwal Gowda
Prajwal Gowda - avatar
+ 2
Have only made it 5 chapters into this self-taught course.. :( i am sure I will eventually get to the more logical stuff :)
18th Oct 2017, 5:15 PM
Aric Dunn
Aric Dunn - avatar
+ 2
It is in control structures part.
18th Oct 2017, 5:19 PM
Prajwal Gowda
Prajwal Gowda - avatar
+ 2
now it is corrected.:)
18th Oct 2017, 5:43 PM
Prajwal Gowda
Prajwal Gowda - avatar
+ 1
haha thats how you use the open list :( I tried soo many different things. never read anywhere to A.append(user) never seen that.. still pretty new lol thank you I figured it would be possible.. instead writing this extremely confusing and not logical crap like this..which I have been trying to write but cant get to work... user = input('Enter Numbers:\n> ') largest = None smallest = None while True: user = input('> ') if user == 'done': try: if largest is None or user > largest: largest = user if smallest is None or user < smallest: smallest = user break except: print('Invalid input') continue print('Maximum ', user) print('Minimum ', user)
18th Oct 2017, 5:10 PM
Aric Dunn
Aric Dunn - avatar
+ 1
darn it the dang "float" lol.. I should have caught that.. though I have never used the .append Thank you :)
18th Oct 2017, 5:46 PM
Aric Dunn
Aric Dunn - avatar
0
hey, just realized this is not giving the correct maximum and min numbers are 7, 2 , bob , 10, 4 n= 0 A=[] count = 0 user = input('Enter Numbers:\n> ') while user != 'done': try: n = n + float(user) count = count + 1 A.append(user) except: print('Enter Numbers or "done"') user = input('> ') avg = n/count if user == 'done': print('Total:',n) print('Count:',count) print('Average:',avg) print('Maximum:',max(A)) print ('Minimum: ',min(A)) output Enter Numbers: > > > Enter Numbers or "done" > > > Total: 23.0 Count: 4 Average: 5.75 Maximum: 7 Minimum: 10
18th Oct 2017, 5:38 PM
Aric Dunn
Aric Dunn - avatar