#Land Game Calculator
game = 1
hamlet = 0
village = 0
town = 0
city = 0
capital = 0
palace = 0
farm = 0
factory = 0
ruins = 0
apolw = 0
apoll = 0
polw = 0
poll = 0
squaresused = hamlet+village+town+city+capital+palace+farm+factory+ruins+apolw+apoll+polw+poll
income = hamlet+(village*2)+(town*3)+(city*4)+(capital*5)+(palace*6)+farm+(factory*3)
while game == 1:
if input("What would you like to do? ") == hamlet:
hamlet = hamlet+(int(input("How many would you like to add? ")))
print("There are now "+str(hamlet)+" of them")
elif input("What would you like to do? ") == village:
village = village+(int(input("How many would you like to add? ")))
print("There are now "+str(village)+" of them")
elif input("What would you like to do? ") == town:
town = town+(int(input("How many would you like to add? ")))
print("There are now "+str(village)+" of them")
答案 0 :(得分:0)
问题在于您要将字符串与整数进行比较。
这取决于input
行:
if input("What would you like to do? ") == hamlet:
此处hamlet
是int
,定义为hamlet = 0
。
另一方面,input()
会返回str
。
input
返回的值永远不会等于hamlet
。
我的意思是,我认为,根据用户键入的内容触发不同的操作。
我猜你希望用户输入"hamlet"
,"village"
或"town"
。
因此,比较应该在那些字符串而不是变量上:
if input("What would you like to do? ") == "hamlet":
答案 1 :(得分:0)
while循环没有正常工作,但是通过更改每个段落中调用if input...
来修复它
command = ""
game = 1
while game == 1:
game = 1
command = input("What would you like to do? ")
if command == hamlet:
hamlet = hamlet+(int(input("How many would you like to add? ")))
print("There are now "+str(hamlet)+" of them")
game = 1
elif command == village:
game = 1
village = village+(int(input("How many would you like to add? ")))
print("There are now "+str(village)+" of them")
game = 1