我已经编写了一个代码,用户输入的金额和他们想要的计算机,如何编写代码告诉他们是否可以负担得起。 (我只有11岁,所以我不希望它过于复杂)
Homebasic_price = 900
Office_price = 1200
Gamer_price = 1500
Studio_price = 2200
price = int(input("How much is the computer you would like?"))
money = int(input("How much money do you have to spend?"))
答案 0 :(得分:2)
basic=100
office=200
game=300
studio=400
price=100
if price < basic:
print("you cant have any PC")
elif price >= basic & price < office:
print("you can have basic machine")
elif print >= office & price < game:
print("You can have office PC")
you can have basic machine
这是一个例子,你可以将你的if-else扩展到其他一些模型。阅读本文以获得更好的想法:https://docs.python.org/3/tutorial/controlflow.html
答案 1 :(得分:2)