Вот мой код:
import os
print("The Arkeyan Text to HTML Converter\n\n")
w = 1
while w == 1:
var1 = input("\n\nWhat would you like the title of your page to be? ")
var2 = input("\nCool! Okay, now what is the text you want inside the body? ")
align = input("\nHow would you like this to be aligned? (center, right or left) ")
background = input("\nFinally, what background colour would you like? (It has to be in RGB format). Press 9 for more info.")
if background == "9":
background = input("\nGo to http://www.w3schools.com/tags/ref_colorpicker.asp to get a colour value and enter it in here: ")
print("\n\nAll done! Here is your personalised code:\n\n")
code = print("<!Doctype html>\n\
<html>\n\
<head>\n\
<title>",var1,"</title>\n\
</head>\n\n\n\
<body bgcolor=\"",background,"\">\n\
<div align=\"",align,"\">\n\
<h1>",var1,"</h1><br>\n\
<p>",var2,"</p>\n\
</div>\n\
</body>\n\
</html>")
my_file = open("C:\output.html", "w")
my_file.write(str(code))
my_file.close()
os.system("C:\\output.html")
x = input("\n\nThank you for using this HTML convert tool. Would you like to generate another code? ")
if x == "yes":
print("\n\n==========UNDERGOING LOOP PROCESS==========\n")
elif x == "no":
print("\n\n==========BREAKING THE LOOP==========\n")
w = 2
else:
print("I don't understand you. Self-destruct sequence initaiated...")
exit()
else:
print("\n\nAll done! Here is your personalised code:\n\n")
code = print("<!Doctype html>\n\
<html>\n\
<head>\n\
<title>",var1,"</title>\n\
</head>\n\n\n\
<body bgcolor=\"",background,"\">\n\
<div align=\"",align,"\">\n\
<h1>",var1,"</h1><br>\n\
<p>",var2,"</p>\n\
</div>\n\
</body>\n\
</html>")
my_file = open("C:\output.html", "w")
my_file.write(str(code))
my_file.close()
os.system("C:\\output.html")
x = input("\n\nThank you for using this HTML convert tool. Would you like to generate another code? ")
if x == "yes":
print("\n\n==========UNDERGOING LOOP PROCESS==========\n")
elif x == "no":
print("\n\n==========BREAKING THE LOOP==========\n")
w = 2
else:
print("I don't understand you. Self-destruct sequence initaiated...")
exit()
HTML-страница открывается хорошо, но она говорит "Нет"! Почему это? Я проверил его несколько раз и, похоже, не могу решить проблему. Вы можете мне помочь? PS Мне нужна моя ошибка исправлена довольно быстро; Я должен отправить его в ближайшее время!
Вы назначаете
print
на "код" (print возвращает None).
print
ничего не возвращает, поэтому code = print(...)
означает, что code
всегда будет None
.
Удалите вызов для print
если вы хотите, чтобы code
был строкой. Вам также понадобится использовать другой метод для форматирования строки. Basic +
concatenation работает или (лучше) использует форматирование строк:
'this is a {} string'.format('formatted')
#this is a formatted string
подробнее читайте в документах.