Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
another problem :)
#11
You don't need a while loop. A while loop would be of use to ask the question over an over again. You only need to do it once. So remove the while loop on line 24, and unindent lines 25-28 once. Note that you will need a conditional eventually, because the assignment requires you to check that the entered value is between 0 and 100.

Also, I would rename the list of scores to 'scores', and rename the variable with the input to 'score'. That would make a little more sense.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#12
i found an error in the 3rd selection changed to as follows:
 elif selection == "3":
       if len(score):
            scores = input("Please enter a score between 0 and 100: ")
            score.append(scores)
            print ('score added to list')
Now i think my list program is complete I just need to add the statement to ensure an error is not generated if a <100 or>1 score is added.
Please look over and give any input as to what i can do if anything to make it cleaner, or any input
COMPLETED code
menu = """
1: Enter to exit
2: List scores so far
3: Add a score
4: Display the highest and lowest scores
"""
score = [ 85.3, 85.2, 21.99 ] 
done = False
finished = False

 
while not done:
    print (menu)
 
    selection = input ("Please enter menu item 1-4: ")
 
    if selection == "1":
        done = True
        print("Thank you for using The score engine")
    elif selection == "2":
        print("Scores recorded so far:")
        print(*score, sep = "\n")
    elif selection == "3":
        if len(score):
            scores = input("Please enter a score between 0 and 100: ")
            score.append(scores)
            print(*score, sep = "\n")
            print ('score added to list')
      
     
    elif selection == "4":
        print("Score engine highest to lowest:")
        score.sort()
        print("Highest score:", max(score), "Lowest score:", min(score))
        
while I was checking everything before posting selection 4 no longer works....ugh I guess something I did to selection 3 (maybe if command) below is error I get

Traceback (most recent call last):
File "C:/Users/raymond/Documents/School/Python/week 4/week 4 program final copy.py", line 42, in <module>
score.sort()
TypeError: '<' not supported between instances of 'str' and 'float'
>>>
Reply
#13
            scores = input("Please enter a score between 0 and 100: ")
            score.append(scores)
input returns you a string and not an integer number.
You need to convert it using int() e.g. score.append(int(scores))

But your naming is very confusing! You name a list with several values "score"
and the input of a single value "scores".
You should consider your variable naming more carefully.
Reply
#14
(Aug-03-2019, 02:09 PM)ichabod801 Wrote: You don't need a while loop. A while loop would be of use to ask the question over an over again. You only need to do it once. So remove the while loop on line 24, and unindent lines 25-28 once.

 elif selection == "3":
        if len(scores):
           score = input("Please enter a score between 0 and 100: ")
           scores.append(score)
           print(*scores, sep = "\n")
           print ('score added to list')
(Aug-03-2019, 02:09 PM)ichabod801 Wrote: Note that you will need a conditional eventually, because the assignment requires you to check that the entered value is between 0 and 100.
I am working on that now

I also changed scores and score
menu = """
1: Enter to exit
2: List scores so far
3: Add a score
4: Display the highest and lowest scores
"""
scores = [ 85.3, 85.2, 21.99 ] 
done = False
finished = False

 
while not done:
    print (menu)
 
    selection = input ("Please enter menu item 1-4: ")
 
    if selection == "1":
        done = True
        print("Thank you for using The score engine")
    elif selection == "2":
        print("Scores recorded so far:")
        print(*scores, sep = "\n")
    elif selection == "3":
        if len(scores):
           score = input("Please enter a score between 0 and 100: ")
           scores.append(score)
           print(*scores, sep = "\n")
           print ('score added to list')
      
     
    elif selection == "4":
        print("Score engine highest to lowest:")
        scores.sort()
        print("Highest score:", max(scores), "Lowest score:", min(scores))
        
Reply
#15
Reread your instructions. You are not supposed to use min() and max() to get the highest and lowest values. Also, you are not sorting before displaying the values, so they may not display in order, as the requirements state.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#16
As per ThomasL post, you are appending strings, but your instruction are
Quote:scores must be floating point numbers
Use https://docs.python.org/3/library/functi...loat#float to return a floating point number.
Reply
#17
UGHHHH back to it..... I will re-read instructions and see what I need to fix. I am aware of the float I was working on that now.
Thank you guys for your help
Reply
#18
I have been working on this way too long and I am sure I am overthinking it. No matter how many times I read the text, you guys attached in regards to "float" and "list highest and lowest " I just can't get it. The wording is just too technical. Can I get some more simplified instruction or hint? I am not wanting anyone to do the homework for me, that is not what I have ever asked. Below is the code I have so far. I think out of all the instructions I have everything complete except adding the float number and however instructor wants the #4 option to work, which should print out as follows: highest score: xxxx lowest score: xxxx

Line 32 is where I was trying to make the highest and lowest work
starting line 24 is where i need to put my float number i think

menu = """
1: Enter to exit
2: List scores so far
3: Add a score
4: Display the highest and lowest scores
"""
scores = [ 85.3, 85.2, 21.99 ] 
done = False

while not done:
    print (menu)
    try:

        selection = input ("Please enter menu item 1-4: ")
        if selection == "1":
            done = True
            print("Thank you for using The score engine")

        elif selection == "2":
            print("Scores recorded so far:")
            scores.sort()
            print(*scores, sep = "\n")
            
        elif selection == "3":
            input("Please enter a score you would like to add to the list from 1-100: ")

        elif selection == "4":
            print("Score engine highest to lowest:")
            scores.sort(reverse)
            #print("Highest score:", max(scores), "Lowest score:", min(scores))
            #print(*scores, sep = "\n")
            print('Highest score:, Lowest score:)
        else:
            print("{} is not a valid entry".format(selection))
            print()
    except ValueError:
        print("Please enter a valid input! ")
        
Reply
#19
You just needed scores.append(float(score)). And you've got the if/elif/else structure for the choice of action, that's all you need to check the value. One check for < 0, one check for > 100, and one check to enter the score. If you sort (without reverse), scores[0] is the lowest number. scores[len(scores) - 1] is the highest value.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#20
(Aug-03-2019, 09:03 PM)ichabod801 Wrote: You just needed scores.append(float(score)). And you've got the if/elif/else structure for the choice of action, that's all you need to check the value. One check for < 0, one check for > 100, and one check to enter the score. If you sort (without reverse), scores[0] is the lowest number. scores[len(scores) - 1] is the highest value.

Thank you I think that will help I briefly tried putting this line on line 28 it didnt work but im sure my structure is wrong, I will do more tomorrow I really have been at this to long it all starts looking the same

print("Highest score is: ",scores[len(scores)-1]"Lowest score is: ",scores(scores)[0]))
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020