缩进错误 python 1
indentation error python 1
我不知道为什么会有缩进区域,但这真的让我很紧张
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
print "Now %s, are you ready for your password to be tested?" % (name)
if raw_input() = "yes"
print "what is your password?"
if raw_input() = "no"
print "Suit yourself, %s!" % (name)
你的程序有很多问题,所以我强烈建议你学习一些教程
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
yes_no = raw_input("Now %s, are you ready for your password to be tested?" % (name))
if yes_no.lower() == 'yes':
print "what is your password?"
if yes_no.lower() == "no":
print "Suit yourself, %s!" % (name)
始终将您的 raw_inputs
分配给一个变量。
例如:
更改此 print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
对此:
name = raw_input("first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
其次
当你使用 if
、for
、while
等时,你必须以 :
结束语句以及任何你想执行的语句只要您的条件成立,就应该缩进。
例如:
if yes_no == 'yes':
print 'Ok'
print 'Ending program'
这样,您的程序布局对用户来说会更加清晰。查看一些教程并尝试一下
首先,当您编写 if
语句时,您的缩进是关闭的。您需要通过一个选项卡将它们带回来 space.
下面是工作代码的示例:
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
print "Now %s, are you ready for your password to be tested?" % (name)
# I fixed the indentation below:
if raw_input() == "yes": #<-- fixed comparison operator here and added colon
print "what is your password?"
if raw_input() == "no": #<-- fixed comparison operator here and added colon
print "Suit yourself, %s!" % (name)
这里我也把=
符号改成了==
。 =
符号是您在声明变量时使用的符号,例如 name = raw_input()
,它创建变量 name
,其值为 raw_input()
.
==
符号是您在比较两个事物时使用的符号,例如 raw_input() == "yes"
,它检查 raw_input()
值是否等于 "yes"
.
感谢 Josh B. 和 letsc,我现在已经完成了代码:
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
yes_no = raw_input("Now %s, are you ready for your password to be tested?" % (name))
if yes_no.lower() == 'yes':
print "what is your password?"
passw = raw_input()
if passw == "password":
print "really? You\'ve got to be kidding me!"
if passw == name:
print "Anybody who knows your name will be able to guess that!"
if passw == dob:
print "Anyone who knows your birthday can guess that!"
if len(passw) < 5:
print "That password may not be long enough, %s" % (name)
if len(passw) > 20:
print "Are you sure you can remeber that?"
else:
print "That\'s a superb password, %s!!" % (name)
if yes_no.lower() == "no":
print "Suit yourself, %s!" % (name)
我不知道为什么会有缩进区域,但这真的让我很紧张
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
print "Now %s, are you ready for your password to be tested?" % (name)
if raw_input() = "yes"
print "what is your password?"
if raw_input() = "no"
print "Suit yourself, %s!" % (name)
你的程序有很多问题,所以我强烈建议你学习一些教程
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
yes_no = raw_input("Now %s, are you ready for your password to be tested?" % (name))
if yes_no.lower() == 'yes':
print "what is your password?"
if yes_no.lower() == "no":
print "Suit yourself, %s!" % (name)
始终将您的 raw_inputs
分配给一个变量。
例如:
更改此 print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
对此:
name = raw_input("first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
其次
当你使用 if
、for
、while
等时,你必须以 :
结束语句以及任何你想执行的语句只要您的条件成立,就应该缩进。
例如:
if yes_no == 'yes':
print 'Ok'
print 'Ending program'
这样,您的程序布局对用户来说会更加清晰。查看一些教程并尝试一下
首先,当您编写 if
语句时,您的缩进是关闭的。您需要通过一个选项卡将它们带回来 space.
下面是工作代码的示例:
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
print "Now %s, are you ready for your password to be tested?" % (name)
# I fixed the indentation below:
if raw_input() == "yes": #<-- fixed comparison operator here and added colon
print "what is your password?"
if raw_input() == "no": #<-- fixed comparison operator here and added colon
print "Suit yourself, %s!" % (name)
这里我也把=
符号改成了==
。 =
符号是您在声明变量时使用的符号,例如 name = raw_input()
,它创建变量 name
,其值为 raw_input()
.
==
符号是您在比较两个事物时使用的符号,例如 raw_input() == "yes"
,它检查 raw_input()
值是否等于 "yes"
.
感谢 Josh B. 和 letsc,我现在已经完成了代码:
print "hello!"
print "I\'m Charlie and I\'m going to test the security of your password!"
print "first I\'d like to know a bit about you! What is your name? (No data is stored!!)"
name = raw_input()
print "Nice to meet you, %s!" % (name)
print "What is your date of birth?"
dob = raw_input()
print "OK! Those answers are used to help me but are forgotten when you close the window!"
yes_no = raw_input("Now %s, are you ready for your password to be tested?" % (name))
if yes_no.lower() == 'yes':
print "what is your password?"
passw = raw_input()
if passw == "password":
print "really? You\'ve got to be kidding me!"
if passw == name:
print "Anybody who knows your name will be able to guess that!"
if passw == dob:
print "Anyone who knows your birthday can guess that!"
if len(passw) < 5:
print "That password may not be long enough, %s" % (name)
if len(passw) > 20:
print "Are you sure you can remeber that?"
else:
print "That\'s a superb password, %s!!" % (name)
if yes_no.lower() == "no":
print "Suit yourself, %s!" % (name)