Python : Need help with output of table
Code:
# Number of students
print('How many students are in the class?')
student_Number = int(input())
# Store list of students who are valid
student_List = []
for i in range(0, student_Number):
# To store current student data
student_Data = []
print('Enter the name of student:')
# Name of Students
student_Name = input()
if len(student_Name)> 24:
print('Name of student cannot exceed 24 characters.')
continue
print('Enter the gpa of student:')
# GPA of Student
student_Gpa = float(input())
if student_Gpa < 0 or student_Gpa > 4:
print('GPA of student must be between 0.0 and 4.0.')
continue
# Adding name to current student
student_Data.append(student_Name)
# Adding gpa to current student
student_Data.append(student_Gpa)
# Adding students to main list
student_List.append(student_Data)
# Displaying Output for valid students
if len(student_List) > 0:
# Header
print('Number Name GPA')
print('-' * 37)
# To store GPA sum
sum_Gpa = 0
# Displaying result for each student
for student in student_List:
student_Number = student_List.index(student) + 1
student_Name = student[0]
student_Gpa = student[1]
#Calculating sum GPA
sum_Gpa += student_Gpa
print(str(student_Number) + ' ' * (10 - len(str(student_Number)) - 1) + student_Name + ' ' * (24 - len(student_Name)) + str(student_Gpa))
# Displaying Average GPA
print("")
print('Average GPA: ' + str(sum_Gpa/(len(student_List))))
Output should look like this: (skips students with long names and GPA not in the range between 0.0 and 4.0.Table assigns students numbers with valid names and GPA)
How many students are in the class?
5
Enter the name of student:
Stan Marsh
Enter the gpa of student:
3.6
Enter the name of student:
Kenny McCormick
Enter the gpa of student:
2.3
Enter the name of student:
Someone with a really long name more than 20 characters
Name of student cannot exceed 24 characters.
Enter the name of student:
Eric Cartman
Enter the gpa of student:
-1.1
GPA of student must be between 0.0 and 4.0.
Enter the name of student:
Kyle Broflovski
Enter the gpa of student:
4.0
Number Name GPA
---------------------------------------------
1 Stan Marsh 3.6
2 Kenny McCormick 2.3
5 Kyle Broflovski 4.0
Average GPA: 3.3000000000000003
please drop a comment if there's a problem. the modifications have been boldened.
#--------------------------------------------------

#-----------------------------------------------------------
# Number of students
print('How many students are in the class?')
student_Number = int(input())
# Store list of students who are valid
student_List = []
number=[]
for i in range(0, student_Number):
# To store current student data
student_Data = []
print('Enter the name of student:')
# Name of Students
student_Name = input()
if len(student_Name)> 24:
print('Name of student cannot exceed 24 characters.')
continue
print('Enter the gpa of student:')
# GPA of Student
student_Gpa = float(input())
if student_Gpa < 0 or student_Gpa > 4:
print('GPA of student must be between 0.0 and 4.0.')
continue
# Adding name to current student
student_Data.append(student_Name)
# Adding gpa to current student
student_Data.append(student_Gpa)
# Adding students to main list
student_List.append(student_Data)
number=number+[i+1]
# Displaying Output for valid students
if len(student_List) > 0:
# Header
print('Number Name GPA')
print('-' * 37)
# To store GPA sum
sum_Gpa = 0
# Displaying result for each student
i=0;
for student in student_List :
student_Number = student_List.index(student) + 1
student_Name = student[0]
student_Gpa = student[1]
#Calculating sum GPA
sum_Gpa += student_Gpa
print(str(number[i]) + ' ' * (10 - len(str(student_Number)) - 1) + student_Name + ' ' * (24 - len(student_Name)) + str(student_Gpa))
i=i+1
# Displaying Average GPA
print("")
print('Average GPA: ' + str(sum_Gpa/(len(student_List))))
#------------------------------------------------------------


Python : Need help with output of table Code: # Number of students print('How many students...
Python: Printing Student Data Ask the user: "How many students are in the class?" Read in the number of students If there are students For each student Ask for the name of the student: "Enter the name of student:" Read in the name of the student If the student's name is greater than 24 characters Do not display this student's data Do not ask for their gpa Print: "Name of student cannot exceed 24 characters." Ask for the gpa of...
in python im trying to get this to print to the file i it created def calculateTotal(): filename = input("Enter a name for the file : ")#ask users for a name for file no_of_students = int(input("Enter the number of students in class : ")) data = [] with open(filename,"w+") as f: for index in range(no_of_students): grades = input("Enter Name of student plus grade :").split() # store the student data in array "data" data.append(grades) # store the total grades in "total"...
For Python 3.7+.
TEST THE CODE WITH THE FOLLOWING GLOBAL CODE AFTER
YOU'RE DONE:
print('\nStart of A2 Student class demo ')
s1 = Student('David Miller', major = 'Hist',enrolled = 'y',
credits = 0, qpoints = 0)
s2 = Student('Sonia Fillmore', major = 'Math',enrolled = 'y',
credits = 90, qpoints = 315)
s3 = Student('A. Einstein', major = 'Phys',enrolled = 'y', credits
= 0, qpoints =
0)
s4 = Student('W. A. Mozart', major = 'Mus',enrolled = 'n', credits
= 29, qpoints...
I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...
I need this python program to access an excel file, books inventory file. The file called (bkstr_inv.xlsx), and I need to add another option [search books], option to allow a customer to search the books inventory, please. CODE ''' Shows the menu with options and gets the user selection. ''' def GetOptionFromUser(): print("******************BookStore**************************") print("1. Add Books") print("2. View Books") print("3. Add To Cart") print("4. View Receipt") print("5. Buy Books") print("6. Clear Cart") print("7. Exit") print("*****************************************************") option = int(input("Select your option:...
Need help writing this code in python.
This what I have so far.
def display_menu():
print("======================================================================")
print(" Baseball Team Manager")
print("MENU OPTIONS")
print("1 - Calculate batting average")
print("2 - Exit program")
print("=====================================================================")
def convert_bat():
option = int(input("Menu option: "))
while option!=2:
if option ==1:
print("Calculate batting average...")
num_at_bats = int(input("Enter official number of at bats:
"))
num_hits = int(input("Enter number of hits: "))
average = num_hits/num_at_bats
print("batting average: ", average)
elif option !=1 and option !=2:
print("Not a valid...
Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX): message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user num = int(input(message)) while num < MINN or num > MAXX: print("Invalid choice!") num = int(input(message)) #return result return num #counts dupes def twoInARow(numbers): ans = "No duplicates next to each...
Python please help! Thanks you
Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...
Using python 3.6 How do I incorporate 0 or negative input to raise an error and let the user try again? like <=0 #loop to check valid input option. while True: try: choice = int(input('Enter choice: ')) if choice>len(header): print("Invalid choice!! Please try again and select value either:",end=" ") for i in range(1,len(header)+1): print(i,end=",") else: break choice = int(input('\nEnter choice: ')) except ValueError as ve:print('Invalid response, You need to select the number choice from the option menu') # Catch your...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...