0
What is the best way to prompt for a decimal value with input containing string (please see the following code)
area = 0 height = input("Please enter the Triangle HEIGHT Value: ") width = input("Please enter the Triangle WIDTH value: ") area = (width * height)/2 print("The area of the Triangle is %.2f: % area)
3 ответов
+ 1
Pls whar language did use for this program
0
string you write in parentheses of input function doesn't do anything with your input.
but, remember - what you get from input is ALWAYS a string, so you need to explicitly convert it to a number if you want a number.
use int(input()) or float(input())
0
Many thanks Demeth!
The code, written in Python is as follows:
print("This program calculates the area of a triangle \nwith a given Width and Height input.")
print(" ")
area = 0
#prompt user for height and width values
height = int(input("What is the HEIGHT value?: "))
width = int(input("What is the WIDTH value?: "))
print(" ")
#Calculate the area of a triangle with input values
area = width * height/2
#printing formatted float value with 2 decimal places
print("The area of the Triangle would be %.2f" % area)