Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_integer(string: str) -> bool:
- """
- This function will check if a string (text) is an integer.
- So we only allow values such as:
- - 1
- - 1.0
- - 100
- But we never allows
- - 1.2
- - 45.221
- - Fiftyfive
- """
- try:
- f = float(string)
- except ValueError:
- return False
- if f.is_integer():
- return True
- else:
- return False
- def get_mark(message: str):
- """
- This function will check if the input is correctly formatted
- and if not will repeat the input.
- It will only accepts integers.
- """
- while(True):
- s = input(message)
- if not is_integer(s):
- print("The input you have given is not valid Mark. Only input numbers. Please try again.")
- continue
- mark = int(float(s))
- if mark < 0 or mark > 100:
- print("A mark can not be smaller than 0 or bigger than 100. Please try again.")
- continue
- # The mark is correctly formatted. We return it.
- return mark
- print("Welcome to Marks percentage calculator")
- print("Here you will be able to find percentage of 5 subjects")
- print("please enter your marks out of 100")
- subjects = [
- "Science",
- "Maths",
- "Social Science",
- "English",
- "Computer",
- ]
- marks = []
- for subject in subjects:
- message = "Enter Your Marks in {}:".format(subject)
- mark = get_mark(message)
- marks.append(mark)
- f = sum(marks) / len(marks) / 100
- o = f * 100
- print("Your Percentage in 5 subjects is", o)
- p = 35
- if o>=p:
- print("congratulations!")
- else:
- print("Better luck next time")
Advertisement
Add Comment
Please, Sign In to add comment