0

I'm a beginner and created a program that asks user to input his percentage and tell him whether his result is good or bad. My code is

per=float(input('Enter your percentage: '))
if per>80%:
    print('Your result is good')
else:
    print('Your result is bad')

But I always get this error

    File "<ipython-input-65-ea1a86d3daa1>", line 2
        if per>80%:
              ^
SyntaxError: invalid syntax

How do I solve it?

1 Answers1

2

You just need to drop the percentage sign % in the if block. Additionally, in case, the user inputs anything with % sign then, you need to take only the numeric parts of the input. Try this :

per = input('Enter your percentage: ')
per = per.replace('%', '')   
per = float(per)
if per>80:
    print('Your result is good')
else:
    print('Your result is bad')
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
  • But I want user to input in percentage format. For example he can enter "85%'. – Munim Jaffer Mar 14 '20 at 13:32
  • If you want the user to be able to enter something like "80%", you will need to strip out the "%" before converting the input to a numeric type. To do this, you can change the first line to `per=float(input('Enter your percentage: ').replace('%',''))`. – Ken Mar 14 '20 at 13:37