我该如何实现呢? [英] How do I make it happen

查看:72
本文介绍了我该如何实现呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python中有这个代码,我想对抗你的年龄



x =输入(给我你的生日)

y =(2018) - (x)

如果y> = 18:

打印(你是成年人)





其他:

z = 18-y

打印(你将成年,z,岁)



我觉得这个错误



TypeError:不支持的操作数类型 - :'int'和'str'



我尝试了什么:



i试图看到互联网,但我没有发现任何东西

i have this code in python that i want to counter your age

x=input("Give me your birthdate")
y=(2018)- (x)
if y>=18:
print("You are adult")


else:
z=18-y
print("You will be adult in", z, years)

and it appear me this error

TypeError: unsupported operand type(s) for -: 'int' and 'str'

What I have tried:

i tried to see in the internet but i didnt found anything

推荐答案

这不好 - 18岁作为一个成年人不仅仅是年 - x的情况。

见这里:使用Age:它与TimeSpan不同! [ ^ ] - 它是基于C#的,所以你可以直接使用它,但这是非常简单的东西,所以你应该能够找出做什么在Python中。
That's not good - "18 years old" as an adult is not just a case of "year - x".
See here: Working with Age: it's not the same as a TimeSpan![^] - it's C# based, so you can;t use it directly, but it's pretty simple stuff so you should be able to work out what to do in Python.


您需要将输入转换为日期类型并从中获取年份。请参阅日期时间 - 基本日期和时间类型 - Python 3.7.1文档 [ ^ ]。
You need to convert the input into a date type and get the year from that. See datetime — Basic date and time types — Python 3.7.1 documentation[^].


这篇关于我该如何实现呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆