不明白为什么这个代码不能打开一个网页

2024-05-23 16:28:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直试图让这个代码为自己工作,但我似乎不能做到这一点。有人能帮忙吗

这是一个代码,它为我打开一个网页。我有一个工作,但它是这么长,不能适应岗位的要求

import webbrowser

# These are the links to the Moodle pages

Agile = 'https://2019.elearning.ait.ie/course/view.php?id=1898'
Digital_Media = 'https://2019.elearning.ait.ie/course/view.php?id=1820'
Comp_Apps = 'https://2019.elearning.ait.ie/course/view.php?id=1647'
Maths = 'https://2019.elearning.ait.ie/course/view.php?id=1902'
Comms = 'https://2019.elearning.ait.ie/course/view.php?id=2244'
Web = 'https://2019.elearning.ait.ie/course/view.php?id=1790'
Software = "https://2019.elearning.ait.ie/course/view.php?id=1903"
Game = "https://2019.elearning.ait.ie/course/view.php?id=1901"

course_name = ['Digital_Media', 'Comp_Apps', 'Maths', 'Comms', 'Web',
               'Agile', 'Software', 'Game', 'end', 'all']  # list of links as strings
links = [Digital_Media, Comp_Apps, Maths, Comms,
         Web, Agile, Software, Game]  # list of links

print('Here are the courses you are doing:\n')
for x in range(len(course_name[0:8])):
    a = (course_name[x])
    print('------>', a)
print('\nShortcuts:\n------> All = open all links\n------> End = end program')

def find_link(name):
    if name == course_name:
        print('Here Is Your Link: {}'.format(links[course_name.find(name)]))
        webbrowser.open(links[course_name.find(name)])


while True:
     try:
         course_name=input('\nEnter Course:')
     except not course_name:
         print('--->Not a course\n')
     else:
         find_link(course_name)

Tags: thenamehttpsviewidlinksfindare