Question
Python: I need help with converting strings to float input without any string formaters like %s ? Input: 5 Stan Marsh 3.6 Kenny McCormick 2.3
Python: I need help with converting strings to float input without any string formaters like %s ?
Input:
5 Stan Marsh 3.6 Kenny McCormick 2.3 Someone with a really long name more than 20 characters Eric Cartman -1.1 Kyle Broflovski 4.0
Output:
How many students are in the class? Enter the name of student: Enter the gpa of student: Enter the name of student: Enter the gpa of student: Enter the name of student: Name of student cannot exceed 24 characters. Enter the name of student: Enter the gpa of student: GPA of student must be between 0.0 and 4.0. Enter the name of student: Enter the gpa of student:
Number Name GPA ------------------------------------- 1 Stan Marsh 3.6 2 Kenny McCormick 2.3 5 Kyle Broflovski 4.0 Average GPA: 3.3000000000000003
My Code:
#Number of students num_of_students=int(input())
for i in range(num_of_students): # Name of student name_of_student=input() # GPA of Students gpa_of_student=input()
print("") print('How many students are in the class?') for j in range(num_of_students): if(len(name_of_student)>=24): print('Name of student cannot exceed 24 characters.') continue print("Enter the name of student:") print("Enter the gpa of student:") if(float(gpa_of_student)<0.0 or float(gpa_of_student)>4.0): print('GPA of student must be between 0.0 and 4.0.') continue print('Enter the name of student:') print('Enter the gpa of student:')
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started