erestum
New Coder
Hi! I am just starting out and am trying to write a dichotomous key to identify minerals. I have a couple questions that I can't figure out...
1) After line 10, how can I get the program to loop them back to the question on line 4?
2) In general how do I get the program to re-ask a question if the appropriate answer isn't there
3) Same kind of loop problem, how can I get it at the end to entirely look back to question on line 11?
4) General feedback, can I make it look better?
[CODE lang="python" title="Key" highlight="10,52"]name = input("Hi! What is your name? ")
print ("Hello " + name + ", nice to meet you. ")
start = input("Do you want to identify a mineral? (y/n)")
if start.lower().strip() == " y":
print ("Great," + name + " ,let's get started")
elif start.lower().strip() == " n":
print ("Ok, " + name + " ,come back when you have a mineral to identify")
else:
print("Try again! ")
questionone = input("Ok, first question, is your mineral metallic or non-metallic?")
if questionone.lower().strip() == "metallic":
mhardness = int(input("Metallic,ok, what is the hardess of your mineral? "))
if mhardness > 4:
print ("A hardness over 4 means the mineral is considered hard. We are narrowing this down! ")
mcolor = input("Hard,ok, what color is your mineral? ")
if mcolor.lower().strip() == "gold":
mcolor = input("Gold, your mineral is pyrite! ")
if mcolor.lower().strip() == "black":
mcolor = input("Black,your mineral is magnetite! ")
if mhardness < 4:
print ("A hardness under 4 means the mineral is considered soft. We are narrowing this down! ")
mcolor = input("Soft,ok, what color is your mineral? ")
if mcolor.lower().strip() == "silver":
mcolor = input("Silver,your mineral is galena! ")
if mcolor.lower().strip() == "gray":
mcolor = input("Gray,your mineral is graphite! ")
elif questionone.lower().strip() == "non-metallic":
nhardness = int(input("Non-metallic,ok, what is the hardess of your mineral? "))
if nhardness > 4:
print ("A hardness over 4 means the mineral is considered hard. We are narrowing this down! ")
print ("A hardness over 4 means the mineral is considered hard. We are narrowing this down! ")
ncolor = input("Hard,ok, what color is your mineral? ")
if ncolor.lower().strip() == "white":
ncolor = input("White, your mineral is feldspar! ")
if ncolor.lower().strip() == "red":
ncolor = input("Red,your mineral is garnet! ")
if nhardness < 4:
print ("A hardness under 4 means the mineral is considered soft. We are narrowing this down! ")
ncolor = input("Soft,ok, what color is your mineral? ")
if ncolor.lower().strip() == "white":
ncolor = input("White,your mineral is calcite! ")
if ncolor.lower().strip() == "yellow":
ncolor = input("Yellow,your mineral is sulfur! ")
answer = input("Do you want to indentify another mineral (y/n) ?")
if answer.lower().strip() == " y":
print ("Great," + name + " ,let's get started")
elif answer.lower().strip() == " n":
print ("Ok, " + name + " ,come back when you have a mineral to identify")[/CODE]
1) After line 10, how can I get the program to loop them back to the question on line 4?
2) In general how do I get the program to re-ask a question if the appropriate answer isn't there
3) Same kind of loop problem, how can I get it at the end to entirely look back to question on line 11?
4) General feedback, can I make it look better?
[CODE lang="python" title="Key" highlight="10,52"]name = input("Hi! What is your name? ")
print ("Hello " + name + ", nice to meet you. ")
start = input("Do you want to identify a mineral? (y/n)")
if start.lower().strip() == " y":
print ("Great," + name + " ,let's get started")
elif start.lower().strip() == " n":
print ("Ok, " + name + " ,come back when you have a mineral to identify")
else:
print("Try again! ")
questionone = input("Ok, first question, is your mineral metallic or non-metallic?")
if questionone.lower().strip() == "metallic":
mhardness = int(input("Metallic,ok, what is the hardess of your mineral? "))
if mhardness > 4:
print ("A hardness over 4 means the mineral is considered hard. We are narrowing this down! ")
mcolor = input("Hard,ok, what color is your mineral? ")
if mcolor.lower().strip() == "gold":
mcolor = input("Gold, your mineral is pyrite! ")
if mcolor.lower().strip() == "black":
mcolor = input("Black,your mineral is magnetite! ")
if mhardness < 4:
print ("A hardness under 4 means the mineral is considered soft. We are narrowing this down! ")
mcolor = input("Soft,ok, what color is your mineral? ")
if mcolor.lower().strip() == "silver":
mcolor = input("Silver,your mineral is galena! ")
if mcolor.lower().strip() == "gray":
mcolor = input("Gray,your mineral is graphite! ")
elif questionone.lower().strip() == "non-metallic":
nhardness = int(input("Non-metallic,ok, what is the hardess of your mineral? "))
if nhardness > 4:
print ("A hardness over 4 means the mineral is considered hard. We are narrowing this down! ")
print ("A hardness over 4 means the mineral is considered hard. We are narrowing this down! ")
ncolor = input("Hard,ok, what color is your mineral? ")
if ncolor.lower().strip() == "white":
ncolor = input("White, your mineral is feldspar! ")
if ncolor.lower().strip() == "red":
ncolor = input("Red,your mineral is garnet! ")
if nhardness < 4:
print ("A hardness under 4 means the mineral is considered soft. We are narrowing this down! ")
ncolor = input("Soft,ok, what color is your mineral? ")
if ncolor.lower().strip() == "white":
ncolor = input("White,your mineral is calcite! ")
if ncolor.lower().strip() == "yellow":
ncolor = input("Yellow,your mineral is sulfur! ")
answer = input("Do you want to indentify another mineral (y/n) ?")
if answer.lower().strip() == " y":
print ("Great," + name + " ,let's get started")
elif answer.lower().strip() == " n":
print ("Ok, " + name + " ,come back when you have a mineral to identify")[/CODE]