我能';由于某些原因,我无法使用Python打开HTML自定义页面
以下是我目前的代码:我能';由于某些原因,我无法使用Python打开HTML自定义页面,python,html,operating-system,converter,Python,Html,Operating System,Converter,以下是我目前的代码: 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? ")
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()
导入操作系统
打印(“Arkeyan文本到HTML转换器\n\n”)
w=1
当w==1时:
var1=input(“\n\n您希望页面的标题是什么?”)
var2=input(“\nCool!好的,现在您希望正文中的文本是什么?”)
align=input(“\n您希望如何对齐?(居中、右或左)”)
background=input(“\n最后,您想要什么样的背景颜色?(必须是RGB格式)。按9键了解更多信息。”)
如果背景==“9”:
背景=输入(“\n到”http://www.w3schools.com/tags/ref_colorpicker.asp 获取颜色值并在此处输入:“)
打印(“\n\n全部完成!这是您的个性化代码:\n\n”)
代码=打印(“\n”\
\n\
\n\
,var1,“\n\
\n\n\n\
\n\
\n\
,var1,“
\n\
,var2,“\n\
\n\
\n\
")
my_file=open(“C:\output.html”、“w”)
my_file.write(str(代码))
我的_文件。关闭()
操作系统(“C:\\output.html”)
x=输入(“\n\n感谢您使用此HTML转换工具。是否要生成其他代码?”)
如果x==“是”:
打印(“\n\n==============================================\n”)
elif x==“否”:
打印(“\n\n=================================================\n”)
w=2
其他:
打印(“我不明白你的意思。自毁序列已启动…”)
退出()
其他:
打印(“\n\n全部完成!这是您的个性化代码:\n\n”)
代码=打印(“\n”\
\n\
\n\
,var1,“\n\
\n\n\n\
\n\
\n\
,var1,“
\n\
,var2,“\n\
\n\
\n\
")
my_file=open(“C:\output.html”、“w”)
my_file.write(str(代码))
我的_文件。关闭()
操作系统(“C:\\output.html”)
x=输入(“\n\n感谢您使用此HTML转换工具。是否要生成其他代码?”)
如果x==“是”:
打印(“\n\n==============================================\n”)
elif x==“否”:
打印(“\n\n=================================================\n”)
w=2
其他:
打印(“我不明白你的意思。自毁序列已启动…”)
退出()
HTML页面打开得很好,但它显示“无”!为什么呢?我已经检查了好几次,似乎无法解决这个问题。你能帮助我吗?另外,我需要很快地纠正我的错误;我必须尽快提交
print
不会返回任何内容,因此code=print(…)
意味着code
将始终是None
如果希望code
成为字符串,请删除对print
的调用。您还需要使用不同的方法来格式化字符串。基本的+
串联可以工作,或者(更好)使用字符串格式:
'this is a {} string'.format('formatted')
#this is a formatted string
请阅读您正在分配的。中的更多内容
print
到“code”(print返回None)。所以我删除了打印元素?在:code=print(“\n\…remove”code=”中