我已经定义了上面的函数mathsquiznormal
等,但是当我运行我的代码时它实际上并没有运行我刚刚结束的函数,有人可以帮助我吗?
def quiz():
quiztype = input("What subject would you like to be quizzed on? Maths or Physics?")
quiztype = quiztype.lower
quizdif = input("What difficulty would you like for your test? Easy, Normal or Hard?")
quizdif = quizdif.lower
if quiztype == "maths" and quizdif == "easy":
mathsquizeasy()
elif quiztype == "maths" and quizdif == "normal":
mathsquiznormal()
elif quiztype == "maths" and quizdif == "hard":
mathsquizhard()
elif quiztype == "physics" and quizdif == "easy":
physicstesteasy()
答案 0 :(得分:1)
我可以指出一些可能导致问题的事情。
首先,你必须调用这样的低级方法quiztype = quiztype.lower()
你现在正在做的是引用低级函数,而不是调用它。
其次,确保缩进正确。
def quiz():
quiztype = input("What subject would you like to be quizzed on? Maths or Physics?")
quiztype = quiztype.lower()
quizdif = input("What difficulty would you like for your test? Easy, Normal or Hard?")
quizdif = quizdif.lower()
if quiztype == "maths" and quizdif == "easy":
print('easy math')
elif quiztype == "maths" and quizdif == "normal":
print ('normal math')
elif quiztype == "maths" and quizdif == "hard":
print ('hard math')
elif quiztype == "physics" and quizdif == "easy":
print ('easy physics')
quiz()
答案 1 :(得分:-1)
您需要使用var添加return
函数quiztype
。你需要...... quizdif
和<template>
<div>
...
<form-input id="name" name="name" v-model="name">Name</form-input>
<form-input id="birth-date" name="birth_date" type="date" v-model="birthDate">Date of Birth</form-input>
<form-input id="avatar" name="avatar" type="file" v-on:triggerChange="onFileChange($event)">Avatar</form-input>
<form-input id="mobile-number" name="mobile_number" type="number" v-model="mobileNumber">Mobile Number</form-input>
...
</div>
</template>
<script>
export default {
data() {
return {
name: null,
birthDate: null,
mobileNumber: null
}
},
methods: {
onFileChange(e) {
let self = this
this.validate(e.target.files[0])
.then(function(res) {
let files = e.target.files,
reader = new FileReader()
// if any values
if (files.length) {
self.removeErrorMessageUpload()
self.files = files[0]
reader.onload = (e) => {
self.updateProfileAvatar(e.target.result)
}
reader.readAsDataURL(files[0])
}
})
.catch(function() {
// do something in the case where the image is not valid
self.displayErrorMessageUpload()
})
},
validate(image) {
let self = this
return new Promise(function(resolve, reject) {
// validation file type
if (!self.allowableTypes.includes(image.name.split(".").pop().toLowerCase())) {
reject()
}
// validation file size
if (image.size > self.maximumSize) {
reject()
}
// validation image resolution
let img = new Image()
img.src = window.URL.createObjectURL(image)
img.onload = function() {
let width = img.naturalWidth,
height = img.naturalHeight
window.URL.revokeObjectURL(img.src)
if (width != 100 && height != 100) {
reject()
}
else {
resolve()
}
}
})
},
}
}
</script>