Advertisement
Mars83

3-3

Oct 3rd, 2011
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #! /usr/bin/env python3.2
  2. # -*- coding: utf-8 -*-
  3.  
  4. # main.py
  5. """ Task: Exercise 3.3
  6.    Write a program to prompt for a score between 0.0 and 1.0. If the score is
  7.    out of range print an error. If the score is between 0.0 and 1.0, print a
  8.    grade using the following table:
  9.    Score Grade
  10.    >= 0.9 A
  11.    >= 0.8 B
  12.    >= 0.7 C
  13.    >= 0.6 D
  14.    < 0.6 F
  15.    Enter score: 0.95
  16.    A
  17.    Enter score: perfect
  18.    Bad score
  19.    Enter score: 10.0
  20.    Bad score
  21.    Enter score: 0.75
  22.    C
  23.    Enter score: 0.5
  24.    F
  25.    Run the program repeatedly as shown above to test the various different
  26.    values for input.
  27. """
  28.  
  29. # Main
  30.  
  31. try:
  32.     score = float(input("Enter score: "))
  33.     if score < 0.0 or score > 1.0:
  34.         raise 1         # simulates an error
  35.     elif score >= 0.9:
  36.         print("A")
  37.     elif score >= 0.8:
  38.         print("B")
  39.     elif score >= 0.7:
  40.         print("C")
  41.     elif score >= 0.6:
  42.         print("D")
  43.     elif score >= 0:
  44.         print("F")
  45.     else:
  46.         raise 1         # simulates an error
  47. except:
  48.     print("Bad score")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement