Python:结果以错误的顺序打印
我目前的代码有问题。我先把结果打印出来,然后在打印之前要打印的单词出现在最后Python:结果以错误的顺序打印,python,python-3.x,output,Python,Python 3.x,Output,我目前的代码有问题。我先把结果打印出来,然后在打印之前要打印的单词出现在最后 # program that converst C to F in a table def main(): print('The given table converst Celsius to Farenheit.'); print('Celsius \t Farenheit'); for C in range(1,21): F=(9/5)*C+32; print( C,"
# program that converst C to F in a table
def main():
print('The given table converst Celsius to Farenheit.');
print('Celsius \t Farenheit');
for C in range(1,21):
F=(9/5)*C+32;
print( C," {0:.1f}".format(F));
main()
告诉我结果
1 33.8
2 35.6
3 37.4
4 39.2
5 41.0
6 42.8
7 44.6
8 46.4
9 48.2
10 50.0
11 51.8
12 53.6
13 55.4
14 57.2
15 59.0
16 60.8
17 62.6
18 64.4
19 66.2
20 68.0
The given table convert Celsius to Fahrenheit.
Celsius Fahrenheit
如果您能帮我解决这个问题,我们将不胜感激。因为for循环超出了主定义,首先for循环被执行,然后是main()。在主定义内移动for循环后,它应该可以正常工作
def main():
print('The given table converst Celsius to Farenheit.');
print('Celsius \t Farenheit');
for C in range(1,21):
F=(9/5)*C+32;
print( C," {0:.1f}".format(F));
main()
将
for
循环移动到main
。谢谢。似乎我已经注意到这一点了。