Python的if语句

1、if-else语句

Tom_age = input('The age of Tom:' )
Mary_age = input('The age of Mary:')
if Tom_age > Mary_age:
     print('Tom older than Mary.')
else:
    print('Mary older than Tom.')
#如果Tom和Mary的年龄一样大怎么办?

输出结果:

The age of Tom:15
The age of Mary:14
Tom older than Mary.

2、if-elif-else

Tom_age = input('The age of Tom:' )
Mary_age = input('The age of Mary:')
if Tom_age > Mary_age:
     print('Tom older than Mary.')
elif Tom_age == Mary_age:
    print('Mary is as old as Tom.')
else:
    print('Tom younger than Mary.')

The age of Tom:11
The age of Mary:11
Mary is as old as Tom.

 

posted @ 2018-01-22 22:50  cross10  阅读(120)  评论(0编辑  收藏  举报