这个简单的脚本不起作用

时间:2017-06-15 06:35:15

标签: python error-handling

这个简单的Python脚本不起作用。

   import time
   import random

    callingcard = ('BootsOnTheGround', 'TitanBaseCamp', 'TitanFacility',
   'TitanicStorm', 'TitanicCanyon', 'TitanSandstorm', 'ToTheShip',
   'AsteroidMines', 'TheSteelDragon', 'C6Assembly', 'C12Patrol')

    weapons = ('Rack-9', 'Karma-45', 'NV-4', 'R3K', 'KBAR-   32', 'Trencher', 'Type-2', 'Volk', 'ERAD', 'FHR40', 'RPR Evo', 'KBS Longbow', 'DMR-1', 'Widowmaker', 'Banshee', 'DCM-8', 'Reaver', 'RAW', 'Mauler', 'Titan', 'EMC', 'Oni', 'Kendall 44', 'Hailstorm', 'OSA', 'MacTav-45', 'TF-141', 'S-Ravage', 'M1', 'Hornet', 'Spartan SA3', 'P-LAW', 'Howitzer')

    while True:
        print("Open Supply Drop?.")
        answer = input().lower()
        if answer == "yes":
            print("Weapons or Calling Card?")
            answer1 = input().lower()
            if answer1 == "Calling Card":
                print("Please wait 3 seconds...")
                time.sleep(3)
               print(random.choice(callingcard))
            elif answer1 == "Weapons":
                print ("Please wait 3 seconds...")
                time.sleep(3)
                print(random.choice(weapons))
            else:
                print("Please wait 3 seconds...")
            time.sleep(3)
            break
       else:
           print("Please wait 3 seconds...")
       time.sleep(3)

2 个答案:

答案 0 :(得分:3)

您将输入视为answer1 = input().lower并将其更改为小写,因此它与任何条件都不匹配。将其更改为answer1 = input()

我已编辑您的代码。

import time
import random

callingcard = ('BootsOnTheGround', 'TitanBaseCamp', 'TitanFacility',
   'TitanicStorm', 'TitanicCanyon', 'TitanSandstorm', 'ToTheShip',
   'AsteroidMines', 'TheSteelDragon', 'C6Assembly', 'C12Patrol')

weapons = ('Rack-9', 'Karma-45', 'NV-4', 'R3K', 'KBAR-   32', 'Trencher', 'Type-2', 'Volk', 'ERAD', 'FHR40', 'RPR Evo', 'KBS Longbow', 'DMR-1', 'Widowmaker', 'Banshee', 'DCM-8', 'Reaver', 'RAW', 'Mauler', 'Titan', 'EMC', 'Oni', 'Kendall 44', 'Hailstorm', 'OSA', 'MacTav-45', 'TF-141', 'S-Ravage', 'M1', 'Hornet', 'Spartan SA3', 'P-LAW', 'Howitzer')

while True:
    print("Open Supply Drop?.")
    answer = input().lower()
    if answer == "yes":
        print("Weapons or Calling Card?")
        answer1 = input()
        if answer1 == "Calling Card":
            print("Please wait 3 seconds...")
            time.sleep(3)
            print(random.choice(callingcard))
        elif answer1 == "Weapons":
            print ("Please wait 3 seconds...")
            time.sleep(3)
            print(random.choice(weapons))
        else:
            print("Please wait 3 seconds...")
        time.sleep(3)
        break
    else:
        print("Please wait 3 seconds...")
    time.sleep(3)

答案 1 :(得分:0)

你正在检查answer1 ==" Weapon1"但在此之前你把它变成了小写。

所以,请删除answer1.lower()或检查answer1 == "weapon1" 然后它会工作......

mohideen@botvfx-dev:~$ python3 ~/Desktop/s.py 
Open Supply Drop?.
yes
Weapons or Calling Card?
weapons
Please wait 3 seconds...
Spartan SA3
mohideen@botvfx-dev:~$