所以我正在做的练习是:
086 Ask the user to enter a new password. Ask them to enter it again. If the two passwords match, display “Thank you”. If the letters are correct but in the wrong case, display th emessage “They must be in the same case”,otherwise display the message “Incorrect”.
我的尝试如下:
passw = input("Enter password: ")
passw2 = input("Enter password again: ")
if passw == passw2:
print("Thank you.")
elif passw != passw2 and passw.lower == passw2.lower:
print("They must be in the same case.")
else:
print("Incorrect.")
但这并没有给我我所希望的结果。 这应该非常简单,但正如你所知,我是初学者:) 预先感谢您!
马塞尔
最佳答案
那个passw.lower
是一个方法,方法本身,你可以调用它来获得小写的密码。还要删除第二个 ìf
中的 passw != passw2
这是强制性的 True
if passw == passw2:
print("Thank you.")
elif passw.lower() == passw2.lower():
print("They must be in the same case.")
else:
print("Incorrect.")
更多
passw = "Abc"
print(passw.lower(), "/", type(passw.lower()))
# abc / <class 'str'>
print(passw.lower, "/", type(passw.lower))
# <built-in method lower of str object at 0x00000202611D4730> / <class 'builtin_function_or_method'>
关于python - python中如何比较两个值是否相同但情况不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67446309/