python模拟输入_如何在Python中模拟用户输入

这里-我修正了calculate_age(),你可以试试“计算年份”。在class AgeCalculator: #No arg needed to write this simple class

def calculate_age(): # Check your sample code, no 'self' arg needed

#age = input("What is your age?") #Can't use for testing

print ('What is your age?') #Can use for testing

age = '9' # Here is where I put in a test age, substitutes for User Imput

age = int(age)

print("Your age is:", age)

#return age Also this is not needed for this simple function

def calculate_year(age): # Again, no 'Self' arg needed - I cleaned up your top function, you try to fix this one using my example

current_year = time.strftime("%Y")

current_year = int(current_year)

calculated_date = (current_year - age) + 100

print("You will be 100 in", calculated_date)

return calculated_date

AgeCalculator.calculate_age()

从我在你的代码中看到的,你应该看看如何构建函数,并且请不要以冒犯的态度对待它。你也可以通过运行它来手动测试你的函数。就你的代码而言,它不会运行。在

祝你好运!在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值