Sep-16-2017, 08:48 PM
Create a program that gives you a character based on a number of points. The points should be taken from the user. If the number of points is not an integer or is outside the scale, an error message should be printed.
Code:
points = input("Please write your score here: ")
if (100>=points and points>=89):
print ("A")
elif (88>=points and points>=77):
print ("B")
elif (76>=points and points>=65):
print ("C")
elif (64>=points and points>=53):
print ("D")
elif (52>=points and points>=41):
print("E")
elif (40>=points and points>=0):
print("F")
else:
print("please write a score between 0 and 100")
What drives me crazy is how to check if user input is an integer or a float. If it is a float i want an error message to appear in the console, like "Please write an integer". If userinput is an integer it should give the appropriate grade. It should be said that i have only learned the basics in python.
I have tried something like this:
a = ''
while a.isdigit() == False:
a = input('Enter a number: ')
But i have not really learned that yet.
Code:
points = input("Please write your score here: ")
if (100>=points and points>=89):
print ("A")
elif (88>=points and points>=77):
print ("B")
elif (76>=points and points>=65):
print ("C")
elif (64>=points and points>=53):
print ("D")
elif (52>=points and points>=41):
print("E")
elif (40>=points and points>=0):
print("F")
else:
print("please write a score between 0 and 100")
What drives me crazy is how to check if user input is an integer or a float. If it is a float i want an error message to appear in the console, like "Please write an integer". If userinput is an integer it should give the appropriate grade. It should be said that i have only learned the basics in python.
I have tried something like this:
a = ''
while a.isdigit() == False:
a = input('Enter a number: ')
But i have not really learned that yet.