Reputation: 21
I'm trying to write a program for a computer programming course to calculate the area of a triangle, and the expected output is "The area is [insert number here]."
Here's what I have, and I'm frankly stumped on the full stop:
b = input('Base: ')
h = input('Height: ')
a = 0.5 * float(b) * float(h)
print('The area is', a, '.')
It outputs this:
Base: 1
Height: 1
The area is 0.5 .
This is marked as incorrect because of the extra space, how do I get rid of it?
Upvotes: 2
Views: 365
Reputation: 71610
The print default separator argument is ' '
(a space), so try changing that to ''
(empty string):
print('The area is ', a, '.', sep='')
Or use +
and make it a string:
print('The area is ', str(a) + '.')
Best with string formatting:
f
string literal:
print(f'The area is {a}.')
Or %s
:
print('The area is %s.' % a)
Or str.format
:
print('The area is {}.'.format(a))
Upvotes: 1