【发布时间】:2019-02-02 01:12:03
【问题描述】:
for i in range(1, 10):
print('temp {}: '.format(i), end = '')
temp = float(input(''))
print(' Celsius = {} Fahrenheit'.format(9 / 5 * temp + 32))
输出是:
temp 1: 0
Celsius = 32 Fahrenheit
temp 2: 5
Celsius = 41 Fahrenheit
我想在上一行打印'Celsius =...'。
我想输出的是:
temp 1: 0 Celsius = 32 Fahrenheit
temp 2: 5 Celsius = 41 Fahrenheit
【问题讨论】:
-
与您的问题无关,但正确的拼写是“Fahrenheit”
-
这里的问题是每当你在 py3 中使用 input() 或在 py2 中使用 raw_input() 时。它读取提示并打印提示。并移至新行。如果连续使用打印语句,则在 py2 中使用“,”,在 py3 中使用 end=''。这些打印语句将打印在同一行中。但是 input() 或 raw_input() 会打印提示,然后移到 STDOUT 中的下一行。
-
发现了一个类似的问题。 stackoverflow.com/questions/7173850/… 根据我们在/通过打印语句中使用 raw_input() 或 input() 时,我们不能在同一行打印它们。除非我们使用 Curses 模块。
标签: python python-3.x input printing