简体   繁体   中英

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>')

finally I got to understand how to use xampp and I finally got to know what is the error then I change my code like here

 `
input_number = form.getvalue('input_number')
if  int(input_number) % 2==0 : 
    answer = "EVEN"
else:
 answer = "ODD"`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM