Guest User

Untitled

a guest
Jul 18th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. def is_integer(string: str) -> bool:
  2.     """
  3.    This function will check if a string (text) is an integer.
  4.    So we only allow values such as:
  5.    - 1
  6.    - 1.0
  7.    - 100
  8.  
  9.    But we never allows
  10.    - 1.2
  11.    - 45.221
  12.    - Fiftyfive
  13.    """
  14.     try:
  15.         f = float(string)
  16.     except ValueError:
  17.         return False
  18.    
  19.     if f.is_integer():
  20.         return True
  21.     else:
  22.         return False
  23.    
  24. def get_mark(message: str):
  25.     """
  26.    This function will check if the input is correctly formatted
  27.    and if not will repeat the input.
  28.    It will only accepts integers.
  29.    """
  30.     while(True):
  31.         s = input(message)
  32.         if not is_integer(s):
  33.             print("The input you have given is not valid Mark. Only input numbers. Please try again.")
  34.             continue
  35.         mark = int(float(s))
  36.         if mark < 0 or mark > 100:
  37.             print("A mark can not be smaller than 0 or bigger than 100. Please try again.")
  38.             continue
  39.         # The mark is correctly formatted. We return it.
  40.         return mark
  41.  
  42.  
  43.  
  44. print("Welcome to Marks percentage calculator")
  45. print("Here you will be able to find percentage of 5 subjects")
  46. print("please enter your marks out of 100")
  47.  
  48. subjects = [
  49.     "Science",
  50.     "Maths",
  51.     "Social Science",
  52.     "English",
  53.     "Computer",
  54. ]
  55.  
  56. marks = []
  57. for subject in subjects:
  58.     message = "Enter Your Marks in {}:".format(subject)
  59.     mark = get_mark(message)
  60.     marks.append(mark)
  61.  
  62. f = sum(marks) / len(marks) / 100
  63. o = f * 100
  64.  
  65. print("Your Percentage in 5 subjects is", o)
  66.  
  67. p = 35
  68. if o>=p:
  69.    print("congratulations!")
  70. else:
  71.    print("Better luck next time")
Advertisement
Add Comment
Please, Sign In to add comment