简体   繁体   English

如何在 Python 3 中进行用户输入

[英]How to make user input in Python 3

I want to create a program that will say correct or incorrect when a user types down a answer.我想创建一个程序,当用户输入答案时,它会说正确或不正确。

I tried using Python storing variables to solve the problem but to no avail我尝试使用Python存储变量来解决问题但无济于事

The code is a bit like this代码有点像这样

    question1 = input ("Type down a password!")
    if input = "bannanas"
      print('Sucess!')

else print("ohhhhh")

But the terminal says但是终端说

File "main.py", line 2
    if input = "bannanas"
             ^
SyntaxError: invalid syntax`enter code here`

Use the comparison operator, == , instead of the assignment operator ( = ):使用比较运算符== ,而不是赋值运算符 ( = ):

question1 = input("Type down a password!")

if input == "bannanas": print('Success!')

else: print("ohhhhh")

You also have a few other syntatical errors, like missing colons (which I added).您还有一些其他语法错误,例如缺少冒号(我添加了)。

Your code must be like below:您的代码必须如下所示:

question1 = input("Type down a password!")
if question1 == 'bannanas':
    print('Sucess!')
else:
    print('ohhhhh')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM