+ 2

Python, How to display string and float in same line

print('This program calculates \n f(x) = x^2 + 10') x=float(input('Entered value of x = ')) print(x) a=(x**2 + 10) print('f(x) = ') print(a) This program calculates f(x) = x^2 + 10 Entered value of x = 10.0 f(x) = 110.0 i wish to display last line of code as f(x)=110.0 but the program is printing 110.0 in the next line. How can i do that? Pleas guide someone

5th Jul 2019, 4:49 AM
Muhammad Murtaza
Muhammad Murtaza - avatar
1 ответ
+ 7
print('f(x) = ', end='') This small change prevents python from adding a new line at the end of the print statement. There are also many other ways to combine the text and variable in a single statement, some examples: print('f(x) = ', a) print('f(x) = ' + str(a)) print(f'f(x) = {a}') print('f(x) = {}'.format(a))
5th Jul 2019, 4:56 AM
Tibor Santa
Tibor Santa - avatar