python代码不会显示在python 3.4.2 shell中(python code not being displayed on python 3.4.2 shell)

编程入门 行业动态 更新时间:2024-10-25 16:20:40
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()

                    
                     
          

更多推荐

本文发布于:2023-07-04 17:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1027051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   python   displayed   code   shell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!