python代码不会显示在python 3.4.2 shell中(python code not being displayed on python 3.4.2 shell)
print("hello")
def vendingMachine():
count = 0
totalCredit = 0
coinNum = int(input("how many coins would you like to enter?:"))
while count in range (coinNum):
coin = float(input("enter coin: £"))
totalCredit = totalCredit + coi
count = count + 1
print("you have £{0} in your bank.".format (round(totalCredit,2)))
print("")
print("choose your item:")
print("")
print("1.coca cola")
print("2.lucozade")
print("3.7up")
print("4.fanta orange")
print("5.pepsi")
print("6.Diet pepsi")
print("7.mountain dew")
print("8.rubicon")
print("9.Dr Pepper")
print("10.sprite")
print("")
finalCredit = totalCredit
round (finalCredit, 2)
item = int(input("enter the number for your item:"))
while item <1 or item >10:
print("this item is not available.")
item = int(input("enter the nuber for your item: "))
if item == 1:
finalCredit = totalCredit - 0.59
print ("you now have a Coca cola can, costing £0.59.")
print ("you have {0} remaining in your bank.".format (round(finalCredit,2)))
当我运行它(f5)时会出现这种情况:
>>> ================================ RESTART =============================== >>> hello >>>我怎么做它所以完整的代码显示不只是'你好'我使用python IDLE 3.4.2我从youtube视频复制这个谢谢
print("hello") def vendingMachine(): count = 0 totalCredit = 0 coinNum = int(input("how many coins would you like to enter?:")) while count in range (coinNum): coin = float(input("enter coin: £")) totalCredit = totalCredit + coi count = count + 1 print("you have £{0} in your bank.".format (round(totalCredit,2))) print("") print("choose your item:") print("") print("1.coca cola") print("2.lucozade") print("3.7up") print("4.fanta orange") print("5.pepsi") print("6.Diet pepsi") print("7.mountain dew") print("8.rubicon") print("9.Dr Pepper") print("10.sprite") print("") finalCredit = totalCredit round (finalCredit, 2) item = int(input("enter the number for your item:")) while item <1 or item >10: print("this item is not available.") item = int(input("enter the nuber for your item: ")) if item == 1: finalCredit = totalCredit - 0.59 print ("you now have a Coca cola can, costing £0.59.") print ("you have {0} remaining in your bank.".format (round(finalCredit,2)))when i run it (f5) this comes up:
>>> ================================ RESTART =============================== >>> hello >>>how do i make it so the full code shows up not just 'hello' im using python IDLE 3.4.2 i copied this from a youtube video thanks
最满意答案
因为你没有打电话给你的功能。 请在python文件的末尾添加这些代码。 然后再运行你的程序。
if __name__ == "__main__": vendingMachine()Because you did not call your function. Please add these code at the end of your python file. And then run your program again.
if __name__ == "__main__": vendingMachine()
更多推荐
发布评论