Python Forum
Help converting int to str value in loop statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help converting int to str value in loop statement
#1
Good evening

The issue i'm trying to solve with this program is I need to convert the code on line 23 to a str value "end" in order to display the average scores.

Thank you very much in advance.
#!/usr/bin/env python3

# display a welcome message
print("The Test Scores program")
print()
print("Enter test scores")
print("Enter 'end' to end input")
print("====================")
# get scores from the user

# initialize the variable for accumulating scores
counter = 0
score_total = 0
test_score = 0

choice = "y"
while choice.lower() == "y":
    test_score = int(input("Enter test score: "))
    if test_score >= 0 and test_score <= 100:
        score_total += test_score
        counter += 1
    
    elif test_score == 999:
        average_score = round(score_total / counter)
        print("======================")
        print("Total Score:  ", score_total,
      "\nAverage Score:", average_score)
        print()
        choice = input("Enter another set of test scores (y/n):")
        if choice =="n":
            break
        print()
        print("Enter test scores")
        print("Enter 'end' to end input")
        print("====================")
        counter = 0
        score_total = 0
        test_score = 0
        continue
    else:
        print("test score must be from 0 through 100. Try again.")
        
print("Bye")
Reply


Messages In This Thread
Help converting int to str value in loop statement - by Jrvelandia - Feb-12-2018, 06:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  While loop and If Statement farzankh 3 3,318 Jan-27-2019, 10:13 PM
Last Post: stullis
  if statement in for loop Danielk121 3 3,786 Nov-13-2017, 01:52 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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