仅使用intern导入python模块

2024-04-19 22:28:50 发布

您现在位置:Python中文网/ 问答频道 /正文

对于我参加的一个编程课程,我们通过一个叫做zybooks的在线教科书来完成所有的工作。对于一个关于模块的作业,我必须创建一个程序,该程序接收一堆数据,然后使用一个模块将其打印为一个表,该模块将为我创建表。我似乎不知道如何通过互联网导入模块,因为如果我在我的电脑上下载,代码将无法在网络浏览器中工作,因为它无法找到模块时,网站评分。有没有什么方法可以让我输入一个URL或使用另一个程序来导入模块并打印出数据表?你知道吗

我遇到的另一个小问题是我们应该检查输入中的错误,我们应该查找的一个错误是输入中有多个逗号。我以为我有正确的解决办法,但并不总是奏效。任何关于如何解决的想法,以及将不胜感激。我引用的代码在第27-29行。你知道吗

print("Enter a title for the data:")
t = input()
print("You entered:", t)
print()

print("Enter the column 1 header:")
c1 = input()
print("You entered:", c1)
print()

print("Enter the column 2 header:")
c2 = input()
print("You entered:", c2)
print()

s = []
i = []

while 1>0:
    print("Enter a data point (-1 to stop input):")
    o = input()
    if o == '-1':
        break
    if ',' not in o:
        print('Error: No comma in string.')
        continue
    if ',,' in o:
        print("Error: Too many commas in input.")
        continue

    x, y = o.split(",", 1)
    try:
        val = int(y)
    except ValueError:
        print("Error: Comma not followed by an integer.")
        continue
    s.append(x)
    i.append(y)
    print("Data string:", x)
    print("Data integer:", y)


import texttable as tt
tab = tt.Texttable()
headings = ['Author Name', 'Number of Novels']
tab.header(headings)

for row in zip(s,i):
    tab.add_row(row)

z = tab.draw()
print (z)

按要求这里是一个样本输入和输出程序,因为它是 enter image description here

这是分级机期望模块产生的结果 enter image description here


Tags: 模块thein程序youinputiferror