Python 如何在for语句中获取数字列表

Python 如何在for语句中获取数字列表,python,for-loop,Python,For Loop,我目前正试图找出如何组织数字 def convert(temp_celsius): return temp_celsius * 1.8 + 32 def table(b): print('C F') for x in b: print('{:10}'.format(convert(x))) table(range(-30, 50, 10)) 我需要一个从-30到40的数字列表,以10步为单位。所以我有两个专栏。一个是法伦海特,一个是摄氏

我目前正试图找出如何组织数字

def convert(temp_celsius):
    return temp_celsius * 1.8 + 32

def table(b):
    print('C        F')
    for x in b:
        print('{:10}'.format(convert(x)))

table(range(-30, 50, 10))

我需要一个从-30到40的数字列表,以10步为单位。所以我有两个专栏。一个是法伦海特,一个是摄氏度。我目前只有转换为Farhenheit的列

实际上只是格式化两个数字而不是一个:

print('{:10} {:10}'.format(x, convert(x)))

当然,您需要修复对齐,但这是您自己可以做的。

有两个格式语句:

for x in b:
    print('{:10} {:10}'.format(x, convert(x)))

当然,您只是忘记添加其他输出。

Er,您已经用
range
完成了。你的问题是什么?@DanielRoseman:他需要同时打印
摄氏度
华氏度
,这是他的问题:)假设他忘了添加另一个
格式()
语句。