mercredi 27 janvier 2021

HTML with Python CGI (if else)

I am doing simple if else in my code but when I put if else, when I run it. It gives me Internal Server Errors. But when I remove if else in the code its working, But I cannot get the correct display, like "The number is EVEN" or "The number is ODD". Its only gives "The number is "

print("Content-type:text/html\r\n\r\n")

import cgi, cgitb.enable()

form = cgi.FieldStorage() 


# Get data from fields
#input_number = form.getvalue('input_number')
input_number=input()
if  input_number % 2==0 : 
    answer = "EVEN"
else:
 answer = "ODD"
   
print('<html>')
print('<head>')
print('<title> The Results of Comparing Odd and Even Numbers</title>')
print('</head>')
print('<body>')
print('<table>')
print('<tr>')
print('<td> The number is   </td>')
 print('<td>    ' + answer + '</td>') 
print('</tr>')
print('</table>')
print('</body>')
print('</html>')

Aucun commentaire:

Enregistrer un commentaire