【发布时间】:2021-12-04 21:37:12
【问题描述】:
输出应该是这样的:
Please enter the miles you drove: 256
Please enter the gallons of gas you put in the tank:
10.1 You got 25.346534653465348 mpg on that tank of gas.
我这样做了:
miles = float(input("Please enter the miles you drove: "))
gallons = float(input("Please enter the gallons you put in the tank: \n"))
print("You got", miles/gallons, "mpg on that tank of gas.")
但显示的输出是:
Please enter the miles you drove: 256
Please enter the gallons you put in the tank:
10.1
You got 25.346534653465348 mpg on that tank of gas.
我需要 10.1 和打印在同一行
我该怎么做?
【问题讨论】:
-
从第二个输入中删除“\n”。
-
虽然问当然是有道理的,但你为什么要这么做?看起来不太好......你真的应该在一行上打印每个问题,在另一行上打印最终输出......
标签: python