120k views
12 votes
Print air_temperature with 1 decimal point followed by C. Sample output from given program: 36.4C Python?

User Leopold
by
5.3k points

2 Answers

4 votes

Answer: print(f'{air_temperature:.1f}C')

Step-by-step explanation:

The letter 'f' indicates that this string is used for formatting. 1f basically means that we are looking for one decimal point. That is how we get the .4 instead of more decimals.

If we had 3f for example, we would see 36.400

We then include C after the brace so that is ends with C.

User Paul Herron
by
5.2k points
9 votes

Answer:

print( f"{round(air_temperature, 1)}C")

Step-by-step explanation:

The print function is a function in python used to output the result of the program. The 'f' is a python3 syntax used to format strings, while the round function is used to return a float number with a specified number of decimal points.

The code above outputs a string of the float number variable air_temperature in celsius.

User Leonard Febrianto
by
4.9k points