如果你们中的任何一个人知道那是什么,我试图从“辐射”系列重拍一个终端。
基本上,程序显示了他们可以选择的一系列选项,然后他们必须输入一个数字(1-5)来选择他们想要查看的内容。程序将使用if语句来确定要查看的内容。例如,如果用户输入了一个,则它将清除屏幕并打印一堆信息,然后用户必须输入回车,然后屏幕清除并再次显示从头开始的选项。整个事情都在while语句中,虽然用户输入不是" C",但它仍会显示所有其他内容,当它变为" C"时,程序将清除所有内容,程序结束。
我知道这一切听起来很混乱,但基本上问题是,如果这个人输入一个数字,它不会做清算事情,它只是再次显示选择。
我只是显示代码,所以如果有人能告诉我问题是什么,那将非常感激。
def confusingFunction():
from os import system
userChoice = ""
while userChoice.upper() != "C":
print("Choice 1")
print("Choice 2")
print("Choice 3")
print("Choice 4")
print("Choice 5")
userChoice = input(">>>")
if userChoice == 1:
system('cls')
print("Stuff")
print("Stuff")
print("Stuff")
input(">>>")
system('cls')
system('cls')
return
答案 0 :(得分:0)
类型转换存在问题。 Python将输入作为字符串。 试试代码
if int(userChoice) == 1:
答案 1 :(得分:0)
如果有人需要整个实际代码,请点击这里......“
locked = False
#Define Function
def accessGranted():
import time
from os import system
userChoice = ""
while userChoice.upper() != "C":
print("Welcome to BunkerSoft Corporations(TM) Terminal\nClearance: Overseer Eyes Only\nBy using this terminal, you are acknowledging that you are an authorized user or technician. Unauthorized users must cease reading and log out of this terminal immediately. Violators will be subject to civil and criminal penalties.\n")
time.sleep(0.1)
print("1. [BUNKER 012 OVERSEER INSTRUCTIONS]")
time.sleep(0.1)
print("2. [Overseer Logs]")
time.sleep(0.1)
print("3. [Experiments]")
time.sleep(0.1)
print("4. [Lab]")
time.sleep(0.1)
print("5. [Cache]\n")
time.sleep(0.1)
userChoice = input(">>>")
while userChoice == 1:
system('cls')
print("Welcome to BunkerSoft Corporations(TM)
Terminal\nClearance: Overseer Eyes Only\n")
print("CONFIDENTIAL CONFIDENTIAL CONFIDENTIAL\nOVERSEER EYES ONLY | VIOLATION BST&A-01001\n")
print("Bunker 012 is designed to research infectious diseases on various lifeforms, including human beings, with particular attention paid to potential mutations in a climate of heavy radiation, with an eventual hope to discover a cure and immunity to this cancerous .")
print("Due to long-term exposure to post-nuclear gamma radiation, infected lifeforms have had their brains permenantly damaged, resulting in complete loss of normal reasoning capabilities and higher thought processes, becoming more animalistic, impulsive, and hostile to anything.")
print("As of the post-nuclear sealment of this bunker, you are aware of the Bunkers two sections. The main section is where a total of 128 Bunker residents can live in for the foreseeable future, and the secret closed off section of the Bunker, with a Bunker door designed not to close properly. This will be where main testing of the effects of gamma radiation will be conducted.")
print("Clinical trials are a vital part of Bunker 012's mission. Trials will be performed in three stages: Firstly, live specimens from outside the bunker will be held captive to study their neurogical and physical subconcious. Secondly, Bunker residents will be asked to enter the vault for screening, where they will unknowingly be exposed to different diseases and cures for the radiation poisoning via propellant nozzles that the resident should suspect is the cleansing spray. Thirdly, the secret Bunker's connection and barrier to the main vault will be open, exposing all the residents to the radiation poisoning, and using the final created cure to cure and immunize the residents.")
print("For your safety and for the scientific staff, you and them will be restricted to the hermetically-sealed research area, and under no circumstance will you engage in direct communication with any of the Bunker residents unless instructed otherwise from BunkerSoft HQ. This measure reduces the chance of cross contamination between Bunker staff and residents.")
print("As a Bunker Overseer, biological and neurogical scientists, and survivor of the nuclear war, you agree that you have been assigned to a task that will bring forth a better future for the last remnants of humanity: to create an ultimate cure to fight the gamma radiation the Chinese communists have plagued us with. Make BunkerSoft proud, Overseer Bridgeman.")
userChoice=input(">>>")
system('cls')
system('cls')
return
def hackingMinigame():
#Import modules
import random
import time
from os import system
#Declare Variables
tryAgain = "Y"
characters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
pwdString = (characters[18], characters[19], characters[14], characters[15])
pwdStop = ''.join(pwdString)
pwdString = (characters[10], characters[8], characters[11], characters[11])
pwdKill = ''.join(pwdString)
pwdString = (characters[19], characters[17], characters[8], characters[15])
pwdTrip = ''.join(pwdString)
pwdString = (characters[18], characters[7], characters[8], characters[15])
pwdShip = ''.join(pwdString)
pwdString = (characters[17], characters[20], characters[11], characters[4])
pwdRule = ''.join(pwdString)
pwdString = (characters[6], characters[17], characters[14], characters[22])
pwdGrow = ''.join(pwdString)
pwdString = (characters[15], characters[0], characters[18], characters[18])
pwdPass = ''.join(pwdString)
pwdString = (characters[22], characters[4], characters[13], characters[19])
pwdWent = ''.join(pwdString)
pwdString = (characters[22], characters[8], characters[13], characters[3])
pwdWind = ''.join(pwdString)
pwdString = (characters[25], characters[14], characters[13], characters[4])
pwdZone = ''.join(pwdString)
passwords = [pwdStop,pwdKill,pwdTrip,pwdShip,pwdRule,pwdGrow,pwdPass,pwdWent,pwdWind,pwdZone]
while tryAgain.upper() == "Y":
attempts = 4
check = ""
userInput = ""
correctPassword = random.sample(passwords,1)
correctPassword = ''.join(correctPassword)
print("Welcome to BunkerSoft Corporations(TM) Terminal")
time.sleep(0.1)
print("Password Required")
time.sleep(0.1)
print("4 Attempts\n")
print("0x587C ;'%@*([}^.'] Ox6030 <_`%[:._^~.$")
time.sleep(0.1)
print("0x588F ^&'KILL*$(#* Ox604G #%^!5>:,>|='")
time.sleep(0.1)
print("0x589H ,&;|$)![}*/, Ox605A GROW|/+&!;^$")
time.sleep(0.1)
print("0x590Y @{=_*}:*=^_{ Ox6068 -*=],&'%`>_}")
time.sleep(0.1)
print("0x591R '`<=%,_<?~%? Ox6073 %`-[{!]{__#<")
time.sleep(0.1)
print("0x592W >'|>%~\$=,#_ Ox608F |./$(%;)!;^$")
time.sleep(0.1)
print("0x593N `.++}[}_TRIP Ox609A ,>:$(PASS^$>")
time.sleep(0.1)
print("0x5945 -_%@*(-]%)|! Ox610S ~!<`*?(WENT@")
time.sleep(0.1)
print("0x5958 `.*+}[}_){'( Ox611Y %@}*-\_`,(:'")
time.sleep(0.1)
print("0x596G \_'\?*#-%*]{ Ox612K +%&{*)~+{;[_")
time.sleep(0.1)
print("0x597C +#-SHIP!>^_[ Ox613L =!];./#%~~<*")
time.sleep(0.1)
print("0x5981 ;'RULE^%!;,> Ox614O #;^WIND)+[|%")
time.sleep(0.1)
print("0x599F (]=){_~`,_<& Ox615U $&%)^'%})!/%")
time.sleep(0.1)
print("0x6006 '>=-`[).$]|] Ox6160 @}*-\_`,(:',")
time.sleep(0.1)
print("0x601L ;'%@*([}^[ST Ox617O %:<{ZONE~]!#")
time.sleep(0.1)
print("0x602I OP@*#;,>?[=] Ox618J |./$(%!)!;^$")
print(correctPassword)
while attempts > 0:
userInput = input(">>>").upper()
if len(userInput) != len(correctPassword):
print("Error")
continue
for i in range(4):
if userInput[i] not in characters:
print("Error")
continue
check = ''
if userInput != correctPassword:
for i in range(4):
if userInput[i] == correctPassword[i]:
check += "X"
attempts = attempts-1
print("Access Denied")
elif userInput == correctPassword:
print("Access Granted")
time.sleep(1)
system('cls')
locked = True
accessGranted()
attempts = 0
continue
if attempts != 0 and check != "XXXX":
print("Likeness =", len(check))
elif attempts == 0 and check != "XXXX":
print("Init Lockout")
if attempts == 0:
tryAgain = input("Reboot? (Y/N)")
system('cls')
return
while locked == False:
hackingMinigame()
这很多,我知道,这非常令人困惑,但我对这应该如何运作的任何建议持开放态度。
答案 2 :(得分:0)
你可以试试这个:
import subprocess
userChoice = ""
while userChoice.upper() != "C":
print("Choice 1")
print("Choice 2")
print("Choice 3")
print("Choice 4")
print("Choice 5")
userChoice = raw_input(">>>")
if userChoice == '1':
subprocess.call('clear')
print("Stuff")
print("Stuff")
print("Stuff")
userChoice = raw_input(">>>")
subprocess.call('clear')
subprocess.call('clear')
答案 3 :(得分:0)
Python 2.x
input
评估您输入的内容并返回评估结果。
因此,当用户输入是数字时,userChoice
为int,当用户输入为字符串时,raw_input
为字符串。
您可以使用input
来避免评估。
Python 3.x
<?php echo Form::open(['method' => 'POST', 'url' => ['/cart/add/'. "{{$product->product_id }}"]] )?>
<?php echo Form::button('Agregar al Carro', ['class' => 'btn-u btn-u-sea-shop btn-u-lg', 'type' => 'submit']) ?>
<?php echo Form::close() ?>
不评估输入的值。