我正在创建一个操作系统,但当它询问我的信息是否正确时,我的安装过程无法正常工作

2024-09-27 02:27:23 发布

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

我正在终端中创建操作系统。我有工作的主要部分,但我已经设计了一个部分,询问您的信息是否良好。这是最难的部分。每当我回答“是”时,它都会重新运行设置,如果我回答“否”,它会发疯

我的意图是,如果您回答“是”,您将获得此elif中的所有内容:

elif truefalsesetup:
    os.system('clear')
    print('Setup has been completed.\n')
    print('Starting tutorial. It will not take long.')
    os.system('clear')
    print('''
    Welcome to the Xenon tutorial.
    Out of the box, Xenon ships with many functions and games!
    ''')

如果您回答否,整个代码块将再次运行(这就是为什么会有一个巨大的while循环)。 我尝试过重做if语句,添加while循环,一大堆东西!任何帮助都将不胜感激

import os, sys, random, re
import blessed as termtools

t = termtools.Terminal()
rerunsetup = True

while rerunsetup:
    os.system('clear')

    print(t.bright_blue_bold('Wᴇʟᴄᴏᴍᴇ ᴛᴏ Xᴇɴᴏɴ Sᴇᴛᴜᴘ.'))
    print('\nThis looks like your first time using Xenon.')
    print('\nXenon is a fast, lightweight os built purely in Python.')
    print('\nTo get started, Xenon needs you to answer a couple questions for the optimal user experience.')

    def getInput():
        userName = str(input('\nFirst, what is your name? '))
        if userName.isalpha():
            userName = re.sub(r'[^A-Za-z]', '', userName)
            userName = userName.capitalize()
        else:
            userName = 'Name not specified.'

        favColor = str(input('\nSecond, what is your favorite color? '))
        if favColor.isalpha():
            favColor = re.sub(r'[^A-Za-z]', '', favColor)
            favColor = favColor.capitalize()
        else:
            favColor = 'Favorite color not specified.'

        age = str(input('\nThird, what is your age? '))
        if age.isdigit():
            age = re.sub('[^0-9]', '', age)
        else:
            age = 'Age not specified.'

        print(f'\nName: {userName}\nFavorite Color: {favColor}\nAge: {age}\n')

    getInput()

    goodInput = str(input('Does this info look good? [y|n] '))
    goodInput = re.sub(r'[^A-Za-z]', '', goodInput)
    goodInput = goodInput.lower()

    if 'y' in goodInput:
        truefalsesetup = False
    elif 'n' in goodInput:
        truefalsesetup = True
    else:
        goodInput = str(input('Does this info look good? [y|n] '))
        goodInput = re.sub(r'[^A-Za-z]', '', goodInput)
        goodInput = goodInput.lower()

    while truefalsesetup:
        if not truefalsesetup:
            print('Oops! Here, try again!')
            getInput()
        elif truefalsesetup:
            os.system('clear')
            print('Setup has been completed.\n')
            print('Starting tutorial. It will not take long.')
            os.system('clear')
            print('''
            Welcome to the Xenon tutorial.
            Out of the box, Xenon ships with many functions and games!
            ''')
        else:
            print("Answer not given in acceptable form. Try again.")

Tags: thereageifosusernamenotsystem

热门问题