簡體   English   中英

將模塊文件導入python

[英]importing a module file into python

我開始學習python。 我編寫了以下要導入到python中的模塊文件,但是IDLE中的輸出未顯示任何內容。 請幫忙

def main():
    print("This program illustrates a chaotic function")
    x=eval(input("enter a number between 0 and 1:"))
    for i in range(10):
        x=3.9*x*(1-x)
        print(x)

main() 

我使用import chaos命令導入模塊,但未顯示任何輸出。

------- chaos.py ----------

def main():
    print("This program illustrates a chaotic function")
    x=eval(input("enter a number between 0 and 1:"))
    for i in range(10):
        x=3.9*x*(1-x)
        print(x)

------- fileimport.py ---------

import chaos
chaos.main()

注意這兩個文件應該在同一目錄中

Parent Folder
          |
          |----chaos.py
          |----fileimport.py

主程序

import chaos
print(chaos.hello())

chaos.py

def hello():
   return "hello"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM