我需要以下代码的帮助。
phone = input("What is the make of your Phone? ")
if phone == "Samsung":
model1 = input("Now can you tell me the model of your phone?")
if model1 < int(4):
print ("This model and any older models are not compatible with this system, Sorry for any inconvenience!")
else:
print ("Let us move on to the problem")
elif phone == "Apple":
model2 = input("Now can you tell me the model of your phone?")
if model1 < 4:
print("This model and any older models are not compatible with this system, Sorry for any inconvenience!")
else:
print("Let us move on to your problem")
你能告诉我如何做到这一点,当你输入少于4的东西时,它会说“模型不兼容”,当它高于4时,它将继续代码。谢谢
当我在
中键入数字时会发生这种情况What is the make of your Phone? Samsung
Now can you tell me the model of your phone?3
Traceback (most recent call last):
File "\\shs-homes01\011275$\GCSE Computing\MY TroubleShooting code.py", line 9, in <module>
if model1 < int(4):
TypeError: unorderable types: str() < int()
答案 0 :(得分:1)
问题是你没有将model1转换为int,它是一个字符串,你不能将int与string进行比较。 试试这个:
if int(model1)<4
如果是你的
,那么下一个其他地方也是如此答案 1 :(得分:1)
尝试更改
if int(model1) < 4:
到
public logIn() {
let phone = this.user.number.replace(/\s+/g, '');
let email = 'u' + phone + '@lunch24.com';
this.af.auth.login({email: email, password: this.user.password})
.then((state) => {
console.log(state)
var usersRef = firebase.database().ref('v1/users');
this.af.database.object(usersRef.child(state.uid))
.subscribe((snapshot) => {
console.log(snapshot)
var user = snapshot;
if (user.roles.driver != true) {
if (user.roles.admin) {
var admin = 1;
} else {
var admin = 0;
}
if (user.roles.operator) {
var operator = 1;
} else {
var operator = 0;
}
if (user.roles.individual_customer) {
var individual_customer = 1;
} else {
var individual_customer = 0;
}
你也需要尝试异常处理。