Intro to Prog 16

Valid GPA

  • Fun and engaging assignments with automatic grading and feedback.
  • Code directly in CodeGrade's online IDE from a starter template.
  • A curriculum designed by the best high school in California.
Developed in collaboration with
The University of Edinburgh logo

Pre-requisites:

Learning goals:

  • Learn how to use the `while` loop to read a `float`.

Task:

Your GPA, or Grading Point Average, is an average of all the grades of a student, calculated by assigning each letter grade a numerical value (for instance, an A has a value of `4.0`). A GPA is always between `0.0` and `4.0`.

Write a program called `validgpa.py` that uses a `while` loop to repeatedly ask the user to enter a valid unweighted GPA (a floating point number between `0.0` and `4.0`). Print “Invalid.” and try again if the given GPA is invalid and print “Thanks.” if the GPA is valid.

Get access to an autograder and online IDE for this assignment now!

Example output:

-!- CODE language-text -!-Enter a valid unweighted GPA: -9
       Invalid.
Enter a valid unweighted GPA: 20.3
       Invalid.
Enter a valid unweighted GPA: 3.7
Thanks.

Learn more:

Start teaching Python now

CodeGrade is your virtual teaching assistant in your Python classroom. You teach, CodeGrade takes care of the rest.

Our 35 built-in fully automatically graded Introduction to Programming assignments are designed especially for middle school and high school coding education, in close collaboration with Harvard-Westlake School (Los Angeles, CA). You can start teaching Python at your school with confidence now. Or, easily scale your classroom with CodeGrade's tools.

Book a personal 30-minute demo now and we'll show you how to get started with CodeGrade in less than 1 hour!

Book a demo now!

Happy teachers

  • Teachers who use CodeGrade have less stress.
  • Teachers who use CodeGrade have happier and more successful students.
  • Teachers who use CodeGrade have a simpler teaching workflow.

Schedule a personalized tour of CodeGrade today.