R
R
Rass2020-05-14 20:11:45
Python
Rass, 2020-05-14 20:11:45

Python help a newbie?

Good day to all, I decided to study programming from books, it turns out a little, tell me with a simple question, maybe stupid, but I don’t understand.
I write the script
a=4
b=5
c=9
print("c","-b","=",a)

Why does it give it out later like this
cb=4
I need to get an answer in numbers instead of letters

what and where I'm doing wrong how right

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Sokolov, 2020-05-14
@IRass

a=4
b=5
c=9

print('{2:d}-{1:d}={0:d}'.format(a, b, c))

# выведет: 9-5=4

In simple terms about formatting
{2:d} , this is the place to display the value. 2 is the position of the argument, the third will go here, c.
After the colon, format dmeans number.

E
ediboba, 2020-05-15
@ediboba

if python is fresh, then you can use f-string:
print(f"{c}-{b}={a}")

Z
zexer, 2020-05-14
@zexer

Instead of "c", write str(c), respectively, the same with b.
And open at least the textbook, seriously.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question