Steel Grade Program in Python


A certain grade of steel is graded according to the following conditions:

  1. Hardness must be greater than 50
  2. Carbon content must be less than 0.7
  3. Tensile strength must be greater than 5600

The grades are as follows:

  1. Grade is 10 if all three conditions are met
  2. Grade is 9 if conditions (i) and (ii) are met
  3. Grade is 8 if conditions (ii) and (iii) are met
  4. Grade is 7 if conditions (i) and (iii) are met
  5. Grade is 6 if only one condition is met
  6. Grade is 5 if none of the conditions are met

Write a program, which will require the user to give values of hardness, carbon content and tensile strength of the steel under consideration and output the grade of the steel.

This program is a basic implementation of a program that assigns a grade to a type of steel based on its hardness, carbon content, and tensile strength.

  • The program then uses a series of "if" statements to check if the input values meet certain criteria. If the hardness is greater than 50, the variable hs_f is set to 1. If the carbon content is less than 0.7, the variable cc_f is set to 1. If the tensile strength is greater than 5600, the variable ts_f is set to 1.
  • Next, the program uses a series of "elif" statements to assign a grade to the steel based on the values of the hs_f, cc_f, and ts_f variables. If none of the input values have failed the criteria check, the steel is assigned a grade of 5.
  • If any one of the input values have failed the criteria check, the steel is assigned a grade of 6. If the hardness and tensile strength have failed the criteria check, the steel is assigned a grade of 7.
  • If the carbon content and tensile strength have failed the criteria check, the steel is assigned a grade of 8. If the hardness and carbon content have failed the criteria check, the steel is assigned a grade of 9.
  • If all the input values have failed the criteria check, the steel is assigned a grade of 10.
  • The program then prints the assigned grade to the console using the "print" function.
  • This program will work for any input values of hardness, carbon content, and tensile strength and assigns the grade to the steel according to the condition mentioned in the program.

Source Code

"""
    hs = Hardness of steel
    cc = Carbon content
    ts = Tensile strength
    """
hs_f=0
cc_f=0
ts_f=0
hs = float(input("Enter the value of Hardness : "))
cc = float(input("Enter the value of Carbon Content: "))
ts = float(input("Enter the value of Tensile Strength: "))
if (hs>50):
	hs_f=1
if (cc<0.7):
	cc_f=1
if (ts>5600):
	ts_f=1
if(hs_f==0 and cc_f==0 and ts_f==0):
	grade = 5
elif(hs_f==1 or cc_f==1 or ts==1):
	grade = 6
elif(hs_f==1 and cc_f==0 and ts_f==1):
	grade = 7
elif(hs_f==0 and cc_f==1 and ts_f==1):
	grade = 8
elif(hs_f==1 and cc_f==1 and ts_f==0):
	grade = 9
#elif(hs_f==1 and cc_f==1 and ts_f==1):
else:
	grade = 10
 
print("The Grade of Steel  :", grade)

Output

Enter the value of Hardness : 23
Enter the value of Carbon Content: 45
Enter the value of Tensile Strength: 26
The Grade of Steel  : 5


Example Programs