我认为使用变量将是解决此问题的更有效方法。观察:
print(""""
1. strength \n
2 Health\n
3. wisdom\n
4. dexterity
5. remove 1 strength for point
6. remove 1 health for point
7. Remove 1 wisdom for point
8. remove 1 dexterity for point
""")
points=30
strength=0
health=0
wisdom=0
dexterity=0
default=1
while default:
choice=int(input("Select attributes that you want:"))
if choice==1:
strength+=1
points-=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ")
elif choice==2:
health+=1
points-=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ", dexterity)
elif choice==3:
wisdom+=1
points-=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ", dexterity)
elif choice==4:
dexterity+=1
points-=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ", dexterity)
elif oc==5:
strength-=1
points+=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ", dexterity)
elif oc==6:
health-=1
points+=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ", dexterity)
elif oc==7:
wisdowm-=1
points+=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ", dexterity)
elif oc==8:
dexterity-=1
points+=1
print("Strength: ", strength, "\nHealth: ", health, "\nWisdom: ", wisdom, "\nDexterity: ", dexterity)
当然你也可以使用字典,但是变量的想法要容易得多,而且编程就是要效率。