Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
another problem :)
#21
In the code you just posted, the first indexing of scores is the right syntax, the second one is the wrong syntax. It's just sequence[index].
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#22
I am back at it I was able to get option 3 working I think it is right anyway. Thank you for making it easier to understand.
this is what I have for option 3
elif selection == "3":
        score = input ("Please enter a score between 0 and 100: ")
        scores.append(float(score))   
        scores.sort()
        print ('score added to list')
Reply
#23
That correctly gets a float in the list. But remember, you have to make sure the float is between 0 and 100.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#24
Well, I have a couple of hours left before the assignment is due and I am beating my head on the wall.
This is what I have so far and #notes what I need to figure out
I went back over and over again to try to understand what you wrote but I cant get it.

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")
#selection 3 I need to ensure a number les than 1 and more than 100 can not be entered (message stating invalid entry)             
        elif selection == "3":
            score = input ("Please enter a score between 0 and 100: ")
            scores.append(float(score))   
            scores.sort()
            print ('score added to list')
#selection 4 I need to list the highest and lowest number in the list            
        elif selection == "4":
            print("Score engine highest to lowest:")
            print("lowest score is: ", scores[len(scores)-1])
            print("highest score is: ", scores(scores)[0])
            
        else:
            print("{} is not a valid entry".format(selection))
            print()
    except ValueError:
        print("Please enter a valid input! ")
         
Reply
#25
Check post #19 in this thread. It tells you the indexes you need for lowest and highest scores. Then you just need the right if/elif structure for the 0 to 100 check:

if <too low/>:
    print(low_warning)
elif <too high/>:
    print(high_warning)
else:
    # do the append
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#26
Thank you I think I am going to have to take the hit.....I have typed, retyped, lost my work due to not saving a good working file (i need to figure that out soon), I just dont get it and I know it is right there and basic stuff I am just burnt.....thank you again for the help it is appreciated more than you know
Reply
#27
Since it appears the due date is done for this one, here is what I was trying to show you:

MENU = """
1: Exit
2: Display scores
3: Add a score
4: Display lowest and highest scores

Enter your choice: """

scores = [85.3, 85.2, 21.99]

while True:
    choice = input(MENU).strip()

    if choice == '1':
        print('\nThank you for using the score engine.')
        break
    elif choice == '2':
        scores.sort()
        print('\nScores entered so far:', ', '.join(['{:.2f}'.format(score) for score in scores]))
    elif choice == '3':
        new_score = float(input('\nPlease enter a score between 0 and 100: '))
        if new_score < 0:
            print('That score is too low.')
        elif new_score > 100:
            print('That score is too high.')
        else:
            scores.append(new_score)
    elif choice == '4':
        scores.sort()
        print('\nThe scores range from {:.2f} to {:.2f}.'.format(scores[0], scores[len(scores) - 1]))
    else:
        print('\nThat selection is invalid. Please enter a number from 1 to 4.')
Output:
1: Exit 2: Display scores 3: Add a score 4: Display lowest and highest scores Enter your choice: 3 Please enter a score between 0 and 100: 80.108 1: Exit 2: Display scores 3: Add a score 4: Display lowest and highest scores Enter your choice: 3 Please enter a score between 0 and 100: 801 That score is too high. 1: Exit 2: Display scores 3: Add a score 4: Display lowest and highest scores Enter your choice: 3 Please enter a score between 0 and 100: -1 That score is too low. 1: Exit 2: Display scores 3: Add a score 4: Display lowest and highest scores Enter your choice: 2 Scores entered so far: 21.99, 80.11, 85.20, 85.30 1: Exit 2: Display scores 3: Add a score 4: Display lowest and highest scores Enter your choice: 4 The scores range from 21.99 to 85.30. 1: Exit 2: Display scores 3: Add a score 4: Display lowest and highest scores Enter your choice: 1 Thank you for using the score engine.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#28
HA HA I was hoping someone would show me so I know.......I completely see it now. I am still learning the structure and the placement of strings which is the most confusing part. Thank you very much for helping me along the way. I really enjoy this even though it is so frustrating to spend hours trying to figure out a line.
Reply
#29
elif selection == "2":
scores.sort(reverse=True)
print('\nScores entered so far: \n', ' '.join(['\n {:.2f}'.format(score)

for those of you who have to have a new line when displaying scores and need them to display highest to low

do you understand why you are putting in the codes?
Reply


Forum Jump:

User Panel Messages

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