我對Python非常陌生。當條件不滿足時,我需要循環回代碼中的特定點。Python while循環回代碼中的特定點
下面是代碼:
# Get user input on VLANs and interfaces to change
print ("what VLAN ID do you want to add? "),
vlan = raw_input()
print ("what interface do you want to add the VLAN to? (e.g. eth10)"),
interface = raw_input()
# Confirm details
print "So we are adding VLAN %r to interface %r" % (vlan, interface)
print ("Are the details above correct? (Yes/No)")
goodtogo = raw_input("> ")
if goodtogo == "yes":
print "Configuring now...."
else:
print "Please fix your error"
while goodtogo != "yes":
print ("Starting again...")
# Some type of code to loop back to start goes here!!
# Runs commands to add gathered config to switch
switch.runCmds(1, ["enable", "configure terminal", "vlan " + vlan, "interface " + interface, "switchport mode access", "switchport access vlan " + vlan, "end" ])
print ("Change completed")
所以我需要發生的是,當「goodtogo」不等於肯定,循環回到代碼的開始。真的不知道該怎麼辦在這裏...
這種行爲通常被稱爲封裝和函數調用 –