0

HELP! I don't know how to add the amount of request per class based on user .....

HELP! I don't know how to add the amount of request per class based on user input from the list. Here are the instructions and my code. a. The Downdog Yoga Studio offers five types of classes, as shown in Table 6-1. Design a program that accepts a number representing a class and then displays the name of the class. b. Modify the Downdog Yoga Studio program so that numeric class requests can be entered continuously until a sentinel value is entered. Then display each class number, name, and a count of the number of requests for each class. classNum = [1,2,3,4,5] classesName = [ "Yoga 1", "Yoga 2", "Children's Yoga", "Prenatal Yoga", "Senior Yoga", "Quit"] userInput = input index = 0 while index != "Quit": userInput = input("Enter a class number or Quit: ") if userInput == "1": print("Yoga 1") elif userInput == "2": print("Yoga 2") elif userInput == "3": print("Children's Yoga") elif userInput == "4": print("Prenatal Yoga") elif userInput == "5": print("Senior Yoga") if userInput == "Quit": print(classesName) print(classNum[index]) print("Done") break

25th Apr 2020, 2:55 AM
Christian Sandoval
Christian Sandoval - avatar
3 Antworten
+ 2
You could, but you better should be DRY (don't repeat yourself), and if your logic is almost good for the (a.), you don't have the (b.) and you need some corrections to let it right work (as not using string but int as list indexes ^^)... Anyway, what's exactly you starting point? Because you've defined 2 lists (classNum and className) and a var 'index' that you not really use (and you pointless assign input function to userInput (wich is overiding at first while loop iteration ^^
27th Apr 2020, 2:21 AM
visph
visph - avatar
0
names = ["Yoga 1","Yoga 2","Children's Yoga","Prenatal Yoga","Senior Yoga"] count = [0 for name in names] print("\nDOWNDOG YOGA STUDIO\n\nlist of available class:") for index, name in enumerate(names): print(" %i: %s" % (index+1,name)) print() while True: try: index = int(input("Enter a class index, or 0 to quit: ")) except: index = -1 if not index: break if index < 0 or len(names) < index: print("Invalid value...") continue index -= 1 count[index] += 1 name = names[index] print("Selected class name:",name) print("\nCount summary of selected classes:") for index, name in enumerate(names): print(" %i: %s => %i" % (index+1,name,count[index])) print()
25th Apr 2020, 11:12 PM
visph
visph - avatar
0
Wow, thats crazy! So much I need to learn. So there was no way to have it count summary the way I did it ?
27th Apr 2020, 2:06 AM
Christian Sandoval
Christian Sandoval - avatar