Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I fix ValueError: Unkownn format code 'f' for object of type 'str' this is how I want it to look as an example

How do I fix ValueError: Unkownn format code 'f' for object of type 'str'

image text in transcribedimage text in transcribed

this is how I want it to look as an example

image text in transcribed

and this is the error i get when i try to format

image text in transcribed

this is my code:

#globals

name_list = []

score_list = []

status_list = []

grade_list = []

def is_valid_graded(grade_basis):

return grade_basis == 1 or grade_basis == 0

def is_valid_score(score): #in range 0...100

return score >=0 and score

def compute_grade(score):

if score > 80:

grade = 'A'

else:

grade = 'B'

return grade

def compute_passfail(score,grade_basis):

if score >= 40:

grade = 'Pass'

else:

grade = 'Fail'

return grade

def submit():

global name_list, score_list, status_list, grade_list

name = input('Enter name?>>')

score = int(input('Enter a score?>>'))

if not is_valid_score(score):

print('Score must be positive')

grade_basis = int(input('Enter 1 for graded, 0 for pass/fail >>'))

if not is_valid_graded(grade_basis):

print('Enter 1 for graded, 0 for pass/fail')

return

grade = compute_grade(score)

grade = compute_passfail(score,grade_basis)

name_list.append(name)

score_list.append(score)

status_list.append(grade_basis)

grade_list.append(grade)

print(f'Name:{name} Score:{score:.2f}')

def compute_average_score():

global score_list

total_score = 0.0

num_inputs = 0

for score in score_list:

total_score = total_score + score

num_inputs = num_inputs + 1

if num_inputs > 0:

avg = total_score / num_inputs

else:

avg = None

return avg, num_inputs

def summary():

average_score, num_inputs = compute_average_score()

if average_score is not None:

print(f'Average Score: {average_score:.2f}\tNumber of Inputs {num_inputs:d}')

else:

print('No Inputs to compute with!')

def clear_lists():

global score_list, name_list, status_list, grade_list

score_list.clear()

name_list.clear()

status_list.clear()

grade_list.clear()

def reset():

clear_lists()

def line():

print('-'* 55)

def display():

global score_list,name_list,status_list, grade_list

if score_list: #strings, and things, when empty, are False.

line()

print(f'|{"Name":^12s}|{"Score":^12s}|{"Status":^14s}|{"Grade":^12s}|')

line()

for name,score,status,grade in zip(name_list, score_list, status_list,grade_list):

print(f'|{name:12.2f}|{score:12.2f}|{status:12.2f}|{grade:12.2f}|')

line()

else:

print('No Data!')

quit = False

while not quit:

print('1.Submit 2.Summary 3.Reset 4.Display 5.Exit')

choice = int(input('Enter choice: '))

if choice == 1:

submit()

elif choice == 2:

summary()

elif choice == 3:

reset()

print('Now ready for new series')

elif choice == 4:

display()

elif choice == 5:

clear_lists()

quit = True

else:

print('Invalid Choice!')

display: global score_list,name_list,status_list, grade_list right justify right justify display() File "u:/IS 320/HW5Q2.py", line 109, in display print(f'l{name:12.2f}|{score: 12.f}|{status:12.2f}|{grade: 12.2d}|') ValueError: Unknown format code 'f' for object of type 'str' DS ITS 220

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

as HighPerforming (out of which

Answered: 1 week ago