Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
another problem :)
#1
First I will say thanks in advance for all your help so far.
Here is the assignment

For remote access, it’s often better to use a Command Line Interface (CLI), rather than a Graphical User Interface (GUI). A CLI does not use a mouse. However, a program can interact with the user via a menu driven interface. In this assignment, you will implement a menu driven interface for maintaining a list of scores. You will also validate user input to make sure that the score entered is within an acceptable range.

Your program should provide a menu driven interface in which the user can do the following:

Choose to exit
Choose to display the scores from highest to lowest values.
Choose to add a score to the list. Note that scores must be floating point numbers.
Choose to display the highest and lowest scores.

Your program should demonstrate secure software best practices as follows:

Create a list with three initial values: 85.3, 85.2 and 21.99.
Use the if/else construct to ensure that new scores entered by the user are between 0.0 and 100.0.
To get the highest and lowest score, sort the list and use indexing. Use the len() function to get the number of items in the list and then subtract 1 to get the index of the last item in the list.
Provide the user with useful information. If the score entered is outside of the range, let the user know if the score is too high or if it's too low. If the user enters an invalid menu selection, let her/him know what's wrong.
Use the print format specifier to set the number of digits to the right of the decimal point to two for the scores displayed.
Your program should include header comments at the top of the file that specify your name, the date, the name of the assignment and the course identifier.

OK this is what I have so far. I wanted to get the frame work finished first to ensure it functioned properly before I got it to add scores.
menu = """
1: Enter to exit
2: List scores so far
3: Add a score
4: Display the highest and lowest scores
"""
List = ["85.3, 85.2, 21.99"] 
done = 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:")
    elif selection == "3":
        print("Please enter a score between 0 and 100:")
        
    elif selection == "4":
        print("Score engine highest to lowest:")
    else:
        print("{} is not a valid entry.".format(selection))
        print()
I am unsure how to get it to record input score and add it to my list of scores and how to sort from higher to lower.
Reply
#2
(Aug-02-2019, 06:02 PM)raymond2688 Wrote: Your program should demonstrate secure software best practices as follows:

Create a list with three initial values: 85.3, 85.2 and 21.99.

You need to fix this first, your list does not comply with this requirement, you have a list with a single item that is a string, it should be a list containing three numbers.
Reply
#3
Once you have fixed what Yoriz pointed out, you can get the number from the user. Use input to get the number as a string, and float to convert the string to a number. Once you've done the check for the range, append it to the list.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
(Aug-02-2019, 06:15 PM)Yoriz Wrote:
(Aug-02-2019, 06:02 PM)raymond2688 Wrote: Your program should demonstrate secure software best practices as follows:

Create a list with three initial values: 85.3, 85.2 and 21.99.

You need to fix this first, your list does not comply with this requirement, you have a list with a single item that is a string, it should be a list containing three numbers.

So i would make my list as follows list = [number, number, number]
removing the quotation marks
Reply
#5
Yes but be careful on the variable naming list is a built in reserved word.
Reply
#6
(Aug-02-2019, 07:16 PM)Yoriz Wrote: Yes but be careful on the variable naming list is a built in reserved word.

I changed it to score

(Aug-02-2019, 06:29 PM)ichabod801 Wrote: Once you have fixed what Yoriz pointed out, you can get the number from the user. Use input to get the number as a string, and float to convert the string to a number. Once you've done the check for the range, append it to the list.

Im am still very new at this sorry.
I understand what a float does and i know that the number entered from my input will present the option i chose. I think i have a grasp on adding another score but i cant tie it all together
Reply
#7
Use the lists append method
https://docs.python.org/3/tutorial/datas...e-on-lists
Reply
#8
(Aug-02-2019, 07:42 PM)raymond2688 Wrote: the number entered from my input will present the option i chose.

That's not the number I'm talking about. That's fine the way it is. If they pick option '3', they will have to enter a number for the new score. That's what you want to convert with float. Then you check it against the range of 1 to 100, and if it's in that range you use the append method that Yoriz linked to.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#9
walking away for the night I will try in the morning
Thank you everyone
Reply
#10
Good morning
I have been working on this for a couple of hours this morning, going over the append command as stated in the tutorial listed above.
I have come a long way (i think) in cleaning this up. I was able to use the append to get a score added to my list, but now it seems after I add the score it wants another score and another score when it should go back to the menu. all other inputs go back to menu so not sure why this one is not
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":
        while 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))
        
Reply


Forum Jump:

User Panel Messages

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