首页 \ 问答 \ 如何编辑变量的值以供以后使用?(How to edit a variable's value for later use? [duplicate])

如何编辑变量的值以供以后使用?(How to edit a variable's value for later use? [duplicate])

这个问题在这里已有答案:

所以我正在设置一个密码管理员以获得乐趣(不打算用于除自学之外的其他任何事情),我希望用户能够编辑他们的用户名和密码。

我设置它的方式是它要求你输入用户名和密码,它会根据几个非常具体的值检查你的响应(第74行),如果语句为真,它将允许访问,如果不是,它会拒绝访问。

然后我尝试设置语句“if(yourUser == yourNewUser and yourPass == yourNewPass):”当我尝试登录时,它给了我一个变量未定义的错误。

所以我尝试在早期定义变量,将每个变量设置为0,这样如果密码不变,它将转到常规位,如果它们已被更改或者如果它们不等于0,它将转到不同的功能做同样的事情,它有点工作,但后来拒绝我访问...

我不知道下一步该尝试什么。 如果您需要对我说的任何内容进行任何澄清,请询问,我会尽力提供帮助。

这是我的代码:

#The goodbye or end statement
def goodbye():
    print('Good Bye! :{D')
#The main password request statement
def request():
    reqPass = input('Which password would you like?[Google, Twitter, Reddit, Computer]')
    #still need to figure out dictionary manipulation so this is a temporary sytem.
    if(reqPass == 'Google' or reqPass == 'google'):
        print('________________')
        print('Pass: GOOGLEPASSHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    elif(reqPass == 'twitter' or reqPass == 'Twitter'):
        print('_________________')
        print('User: TWITTERUSERHERE')
        print('Pass: TWITTERPASSHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    elif(reqPass == 'computer' or reqPass == 'Computer'):
        print('________________')
        print('Pass: COMPUTERPASSHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    elif(reqPass == 'reddit' or reqPass == 'Reddit'):
        print('_________________________')
        print('User: REDDITUSERHERE')
        print('Pass: REDDITPASSHERE')       
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    #This is the start of the changed password function     
def changedpass():
    if(yourUser == yourNewUser and yourPass == yourNewPass):
        dirCheck = input('Account settings?[y,n]')
        if(dirCheck == 'y' or dirCheck == 'Y'):
            #This is the start of the password/username thing
            print('this function is not working yet!')
            actSetCheck = input('Change username or password?')
            if(actSetCheck == 'user' or actSetCheck == 'User' or actSetCheck == 'Username' or actSetCheck == 'username'):
                yourNewUser = input('What would you like your new username to be?')
            elif(actSetCheck == 'pass' or actSetCheck == 'Pass' or actSetCheck == 'password' or actSetCheck == 'Password'):
                yourNewPass = input('What would you like your new password to be?')
        elif(dirCheck == 'n' or dirCheck == 'N'):
            request()

#setting the variables early on
yourNewUser == 0
yourNewPass == 0
#This is the "title screen"    
print('_____This is a password keeper_____')
#checking if the user has an account
actCheck = input('Do you already have an account?')
if(actCheck == 'Yes' or actCheck == 'yes'):
    #Checking to see if the yourNewUser or yourNewPass variable has been changed
    if(yourNewUser != '0' or yourNewPass != '0'):
        changedpass()
    #asking for user's name and password
    else:
        yourUser = input('___What is your Username?___')
        yourPass = input('___What is your Password?___')
        if(yourUser == 'ari' and yourPass == 'rycbar1234'):
            dirCheck = input('Account settings?[y,n]')
            if(dirCheck == 'y' or dirCheck == 'Y'):
                #This is the start of the change password/username thing
                print('this function is not working yet!')
                actSetCheck = input('Change username or password?')
                if(actSetCheck == 'user' or actSetCheck == 'User' or actSetCheck == 'Username' or actSetCheck == 'username'):
                    yourNewUser = input('What would you like your new username to be?')
                elif(actSetCheck == 'pass' or actSetCheck == 'Pass' or actSetCheck == 'password' or actSetCheck == 'Password'):
                    yourNewPass = input('What would you like your new password to be?')
            elif(dirCheck == 'n' or dirCheck == 'N'):
                request()
        #incorrect password thing
        else:
            print('Incorrect Username or password')

This question already has an answer here:

So i'm making a password keeper for fun(not intended to be used for anything other than teaching myself), and I want the user to be able to edit their username and password.

The way I had it set up is it asks you for a username and password, it checks your responses against a couple of very specific values(line 74), if the statement was true, it would allow access and if it isn't, it would deny access.

I then tried to set the statement "if(yourUser == yourNewUser and yourPass == yourNewPass):" it gives me a variable undefined error when I try to log in which I sort of expected.

So I tried defining the variables early on, setting each of them as 0 so if the password is unchanged, it would go to the regular bit, and if they have been changed or if they don't equal 0, it would go to a different function that does the same thing and it sort of worked, but then denied me access...

I don't know what to try next. If you need any clarification on anything that I said, just ask and I'll try to help.

Here's my code:

#The goodbye or end statement
def goodbye():
    print('Good Bye! :{D')
#The main password request statement
def request():
    reqPass = input('Which password would you like?[Google, Twitter, Reddit, Computer]')
    #still need to figure out dictionary manipulation so this is a temporary sytem.
    if(reqPass == 'Google' or reqPass == 'google'):
        print('________________')
        print('Pass: GOOGLEPASSHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    elif(reqPass == 'twitter' or reqPass == 'Twitter'):
        print('_________________')
        print('User: TWITTERUSERHERE')
        print('Pass: TWITTERPASSHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    elif(reqPass == 'computer' or reqPass == 'Computer'):
        print('________________')
        print('Pass: COMPUTERPASSHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    elif(reqPass == 'reddit' or reqPass == 'Reddit'):
        print('_________________________')
        print('User: REDDITUSERHERE')
        print('Pass: REDDITPASSHERE')       
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            request()
        else:
            goodbye()
    #This is the start of the changed password function     
def changedpass():
    if(yourUser == yourNewUser and yourPass == yourNewPass):
        dirCheck = input('Account settings?[y,n]')
        if(dirCheck == 'y' or dirCheck == 'Y'):
            #This is the start of the password/username thing
            print('this function is not working yet!')
            actSetCheck = input('Change username or password?')
            if(actSetCheck == 'user' or actSetCheck == 'User' or actSetCheck == 'Username' or actSetCheck == 'username'):
                yourNewUser = input('What would you like your new username to be?')
            elif(actSetCheck == 'pass' or actSetCheck == 'Pass' or actSetCheck == 'password' or actSetCheck == 'Password'):
                yourNewPass = input('What would you like your new password to be?')
        elif(dirCheck == 'n' or dirCheck == 'N'):
            request()

#setting the variables early on
yourNewUser == 0
yourNewPass == 0
#This is the "title screen"    
print('_____This is a password keeper_____')
#checking if the user has an account
actCheck = input('Do you already have an account?')
if(actCheck == 'Yes' or actCheck == 'yes'):
    #Checking to see if the yourNewUser or yourNewPass variable has been changed
    if(yourNewUser != '0' or yourNewPass != '0'):
        changedpass()
    #asking for user's name and password
    else:
        yourUser = input('___What is your Username?___')
        yourPass = input('___What is your Password?___')
        if(yourUser == 'ari' and yourPass == 'rycbar1234'):
            dirCheck = input('Account settings?[y,n]')
            if(dirCheck == 'y' or dirCheck == 'Y'):
                #This is the start of the change password/username thing
                print('this function is not working yet!')
                actSetCheck = input('Change username or password?')
                if(actSetCheck == 'user' or actSetCheck == 'User' or actSetCheck == 'Username' or actSetCheck == 'username'):
                    yourNewUser = input('What would you like your new username to be?')
                elif(actSetCheck == 'pass' or actSetCheck == 'Pass' or actSetCheck == 'password' or actSetCheck == 'Password'):
                    yourNewPass = input('What would you like your new password to be?')
            elif(dirCheck == 'n' or dirCheck == 'N'):
                request()
        #incorrect password thing
        else:
            print('Incorrect Username or password')

原文:https://stackoverflow.com/questions/36414693
更新时间:2024-01-13 22:01

最满意答案

如果您使用RelativeLayout,则可以轻松地将其他视图对齐到屏幕的顶部/底部:

使用android:layout_alignParentTop="true"

或者android:layout_alignParentBottom="true"

左/右相同:

android:layout_alignParentLeft="true" or android:layout_alignParentRight="true"

那这个呢 ?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" >

<TextView
    android:text="@string/label_left" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true"/>
<TextView
    android:text="@string/label_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true"/>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:gravity="center"
    android:textSize="40sp" 
    android:layout_centerInParent="true"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/next_activity"
    android:gravity="center"
    android:textSize="30sp" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"/>      

这是你在找什么?


If you use a RelativeLayout instead, you can align other views to the top/bottom of the screen easily:

use android:layout_alignParentTop="true"

or android:layout_alignParentBottom="true"

same for left/right :

android:layout_alignParentLeft="true" or android:layout_alignParentRight="true"

What about this ?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" >

<TextView
    android:text="@string/label_left" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true"/>
<TextView
    android:text="@string/label_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true"/>

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:gravity="center"
    android:textSize="40sp" 
    android:layout_centerInParent="true"/>

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/next_activity"
    android:gravity="center"
    android:textSize="30sp" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"/>      

Is it what you are looking for ?

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)