我正在制作一个简单的基于文本的游戏,并得到一个错误。我必须将我的代码中的int转换为str。我的代码如下所示:如何将这个int转换为if语句中的字符串?
tax1 = input("You May Now Tax Your City. Will You? ")
if tax1 == "Yes" or tax1 == "yes":
tax2 = input("How Much Will You Tax Per Person In Dollars? ")
if tax2 > 3:
print("You Taxed To High! People Are Moving Out")
time.sleep(1.5)
population -= (random.randint(2, 4))
print("The Population Is Now " + str(population))
time.sleep(1.5)
money += (population * 2)
print("From The Rent You Now Have $" + str(money) + " In Total.")
if tax2 < 3:
print("You Have Placed A Tax That Citizens Are Fine With.")
time.sleep(1.5)
money += (tax2+(population * 2))
print("From The Rent And Tax You Now Have $" + str(money) + " In Total")
我会在代码中添加哪些内容?
请发布错误和堆栈跟踪。只是告诉我们你得到了一个错误并没有帮助。 –
作为参考,您可能想使用'if tax1.lower()==“yes”'而不是'如果tax1 ==“Yes”或者tax1 ==“yes”' - 读起来会更简单一些用户更多选项(大写和小写的任意组合)。 – thegrinner
你必须照顾一个城市好吗,这就是为什么有税! –