用python创建表

用python创建表,python,html,list,tuples,Python,Html,List,Tuples,我要求一个用户回答一系列问题,然后答案将写入用户桌面上名为mydoc.doc的文件中。我现在遇到的问题是用Python创建一个表,该表创建的行数与用户输入的访谈数相同。因此,如果用户输入5次面试,它会询问他们5次面试的开始/结束时间、面试类型和面试官姓名(每个“面试”都存储在列表中的元组中)。然后,它需要在一行上输出每个元组,但元组中的每个项在不同的列中。我开始在代码中加入HTML标记并构建一个类似的表,但接下来我如何告诉程序做5行,并在不同的列中输入元组中的每一项内容。这就是我到目前为止所拥有

我要求一个用户回答一系列问题,然后答案将写入用户桌面上名为mydoc.doc的文件中。我现在遇到的问题是用Python创建一个表,该表创建的行数与用户输入的访谈数相同。因此,如果用户输入5次面试,它会询问他们5次面试的开始/结束时间、面试类型和面试官姓名(每个“面试”都存储在列表中的元组中)。然后,它需要在一行上输出每个元组,但元组中的每个项在不同的列中。我开始在代码中加入HTML标记并构建一个类似的表,但接下来我如何告诉程序做5行,并在不同的列中输入元组中的每一项内容。这就是我到目前为止所拥有的

import sys
outfile = open( r'/Users/x/Desktop/myDoc.txt', 'w' )
external = raw_input('is this an exernal invite: ')
inhouse = raw_input('is this an in house invite: ')
if external == 'y'and inhouse== 'y':
    cfname= raw_input('What is the Candidte First Name:')
    clname= raw_input('What is the Candidte Last Name:')
    interviewmonth= raw_input('What is the Month of the interview: ')
    interviewday= raw_input('What is the Day of the interview: ')
    cleadfname= raw_input('What is the recrutiers  first name of the interview: ')
    cleadlname= raw_input('What is the recruiters last name of the interview: ')
    i = 0
    lis = []
    n = int(raw_input("How many interviews are there? "))
    while n:
       i += 1
       istart = raw_input("Interview Start Time: ")
       iend= raw_input("Interview End Time: ")
       ipeople= raw_input("What are the interviewer names: ")
       itype= raw_input("What is the interview type: ")
       lis.append((istart, iend, ipeople, itype))
       n-=1
    a = '<html><head></head><body> Hi %s, </br> The interview is scheduled for <strong>%s %sth</strong>\
         <br/>if you have an questions please contact %s\
         <TABLE border=1>\
         <TR>\
         </TR>\
         <TR>\
         <TH>Interviewer</TH>\
         <TH>Interview Type</TH>\
         </TR>\
         <TR ALIGN="CENTER">\
         <TD>Data 1</TD>\
         <TD>Data 2</TD>\
         </TR>\
         </TABLE>\
         </body></html>'% (cfname, interviewmonth, interviewday, cleadfname)
    outfile.write(a)
outfile.close()
导入系统 outfile=open(r'/Users/x/Desktop/myDoc.txt',w') 外部=原始输入('这是外部邀请:') 内部=原始输入('这是内部邀请:') 如果外部=='y'和内部=='y': cfname=raw_输入('Candidte的名字是什么:') clname=raw_输入('Candidte姓氏是什么:') interviewmonth=原始输入(“面试的月份:”) interviewday=原始输入(“面试日期:”) cleadfname=raw_输入('采访的再现者的名字是什么:') cleadlname=raw_输入(“招聘人员在面试中的姓氏是什么:”) i=0 lis=[] n=int(原始输入(“有多少次面试?”) 而n: i+=1 istart=原始输入(“面试开始时间:”) iend=原始输入(“面试结束时间:”) i员工=原始输入(“面试官姓名:”) itype=原始输入(“什么是面试类型:”) lis.append((istart、iend、IPOPLE、itype)) n-=1 a='您好%s,
面试安排在%s%sth\
如果您有任何问题,请与%s联系\ \ \ \ \ 采访者\ 面试类型\ \ \ 数据1\ 数据2\ \ \ “%(cfname、interviewmonth、interviewday、CleadName) 输出文件写入(a) outfile.close()
简单回答,使用循环

首先,我建议不要用i+=1、n-=1和while(n)跳舞 对于范围(n)中的i:

接下来,一旦你用所有的元组建立了你的尼斯lis,循环它

这里有一个示例,大致基于您的示例,但我不必思考并键入值。我在你的代码中查询了一些东西,我在下面的内容中有一些评论要问

#! /usr/bin/python

cfname = "Victim"
interviewmonth = "Januember"
interviewday = "Fooday"
cleadfname = "The Boss"

n = 10
lis = []
for i in range(10):
  istart  = "istart  value %d"%i
  iend    = "iend    value %d"%i
  ipeople = "ipeople value %d"%i
  itype   = "itype   value %d"%i
  lis.append((istart, iend, ipeople, itype))

html = """
<html>
  <head></head>
  <body>
    <!-- Should have a p tag here -->
    Hi %s, 
    </br>The interview is scheduled for <strong>%s %sth</strong>
    <br/>if you have an questions please contact %s
    <!-- Should have a /p tag here -->
"""
print html%(cfname, interviewmonth, interviewday, cleadfname);

html = """
    <TABLE border=1>
      <TR> <!-- Why'd you have this blank line? -->
      </TR>
      <TR>
        <!-- Didn't understand your headings, should it not be the
             things in lis? 
        -->
        <TH>Start</TH>
        <th>End</th>
        <th>People</th>
        <TH>Interview Type</TH>
      </TR>
"""
print html

# Now here's where I think you want a loop
for interview in lis:
  html = """
      <TR ALIGN="CENTER">
        <td>%s</td>
        <td>%s</td>
        <td>%s</td>
        <td>%s</td>
      </TR>
  """
  print html % interview

html = """
    </TABLE>
  </body>
</html>
"""
print html
#/usr/bin/python
cfname=“受害者”
访谈月份=“一月”
interviewday=“Fooday”
cleadfname=“老板”
n=10
lis=[]
对于范围(10)内的i:
istart=“istart值%d”%i
iend=“iend值%d”%i
ipeople=“ipeople值%d”%i
itype=“itype值%d”%i
lis.append((istart、iend、IPOPLE、itype))
html=”“”
您好%s,

面试安排在%s%sth
如果您有任何问题,请与%s联系 """ 打印html%(cfname、interviewmonth、interviewday、CleadName); html=”“” 开始 终点 人 面试类型 """ 打印html #现在我想你需要一个循环 lis中的面试: html=”“” % % % % """ 打印html%采访 html=”“” """ 打印html
您能否举例说明:对于输入X,应生成表Y?