# python编写程序、从键盘输入一个年份_通过计算当年 - 出生年份使用python创建年龄计算器...

# Function Boolean is_valid_integer(String input_string)

# Declare Boolean is_valid

#

# is_valid = is input_string a valid integer?

# Return is_valid

# End Function

def is_valid_integer(input_string):

try:

val = int(input_string)

is_valid = True

except ValueError:

is_valid = False

return is_valid

# Function Integer get_year_born()

# Declare Boolean is_valid

#

# Display "What year were you born in? "

# Input input_string

# Set is_valid = is_valid_integer(input_string)

# While Not is_valid

# Display "Please only enter whole years."

# Input input_string

# is_valid = is_valid_integer(input_string)

# End While

# input_integer = int(input_string)

# Return input_integer

# End Function

def get_year_born():

input_string = input("What year were you born in? ")

is_valid = is_valid_integer(input_string)

while not is_valid:

input_string = input("Please only enter whole years. ")

is_valid = is_valid_integer(input_string)

input_integer = int(input_string)

return input_integer

# Function Integer calculate_difference()

# difference = 2017 - input_integer

# End Function

import datetime

def calculate_difference(difference):

difference = 2017 - input_integer

return difference

# Module calculate_age_year()

# Set born = get_year_born()

# Call calculate_difference()

# End Module

def calculate_difference():

calculate_age_year()

+0

+0

+0

• 0
点赞
• 1
收藏
觉得还不错? 一键收藏
• 0
评论
10-27 7795
07-12 4383
06-07 173
05-01 1114
09-19 644

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、付费专栏及课程。