忽略正确导入的模块

时间:2019-09-26 05:14:49

标签: python

因此,我正在学习Python入门课程,尝试学习我的第一门语言。我已经做到了这一点,但是我为此感到挣扎。我想使用模块来执行功能。但是,它似乎完全忽略了我的模块。

有什么建议吗?

import asgn4_module as mod
"""
imports the module, and then prints intro
"""
print ("Assignment 4")
print ()

"""
prompts for names and age.
If they're blank, reprompts them.
"""

firstname = (input ("Please enter your first name."))
while mod.is_field_blank (firstname):
    print ("First Name must be entered.")
    firstname = (input ("Please enter your first name."))
    continue
lastname = (input ("Please enter your last name."))
while mod.is_field_blank (lastname):
    print ("Last name must be entered.")
    lastname = (input ("Please enter your last name."))
    continue
age =(input ("Please enter your age."))
while mod.is_field_blank (age):
    print ("Age must be entered.")
    age =(input ("Please enter your age."))
    continue
while mod.is_field_a_number (age):
    print ("Age entered must be a number.")
    age =(input ("Please enter your age."))
    continue
"""
inputs all received properly, print message calling those variables, then prints the end
"""
if int(age) >= 40:
    print ("Well, " + firstname + " " + lastname + "it looks like you're over the hill.")
else:
    print ("It looks like you have many programming years ahead of you, " + firstname + " " + lastname)
print ()
print ("End of assignment 4")

这是asgn4_module.py

"""
this module determines if the string is blank, or a number.
"""

def is_field_blank (string):
    string == ""

def is_field_a_number (string):
    string is int

1 个答案:

答案 0 :(得分:0)

您不是要检查为空,而是针对'g'输入字符串,我认为这是不正确的,因为您已经解释了代码。而且您还必须返回案件条件。

像这样更新您的模块

"""
this module determines if the string is blank, or a number.
"""

def is_field_blank (string):
    return False if len(string) else True

# for python3
def is_field_a_number (string):
    return not string.isnumeric

对于python2

# for python2
def is_field_a_number (string):
    return not isinstance(string, int)