python how to repeat code

前端 未结 3 1032
灰色年华
灰色年华 2020-12-20 10:56

I am a very beginner in python and I want to repeat this code. But I dont\'t really know how to do this without \"goto\". I tried to learn about loops for hours but still n

3条回答
  •  既然无缘
    2020-12-20 11:10

    Create a function repeat and add your code in it. Then use while True for infinite call or for i in range(6) for 6 times call`:

    import requests
    def repeat():
      addr = input()
      vendor = requests.get('http://api.macvendors.com/' + addr).text
      print(addr, vendor)
    while True:
      repeat()
    

    Note that goto is not recommended in any language and is not available in python. It causes a lot of problems.

提交回复
热议问题