#!/usr/bin/python
# Filename: if.py
number = 23
guess = int(raw_input('Enter an integer : '))
if guess == number:
print 'Congratulations, you guessed it.' # New block starts here
print "(but you do not win any prizes!)" # New block ends here
elif guess < number:
print 'No, it is a little higher than that' # Another block
# You can do whatever you want in a block ...
else:
print 'No, it is a little lower than that'
# you must have guess > number to reach here
print 'Done'
# This last statement is always executed, after the if statement is executed
$ python if.py Enter an integer : 50 No, it is a little lower than that Done $ python if.py Enter an integer : 22 No, it is a little higher than that Done $ python if.py Enter an integer : 23 Congratulations, you guessed it. (but you do not win any prizes!) Done
if True: print 'Yes, it is true'
#! /usr/bin/env python
#coding:utf-8
print "请输入任意一个整数数字:"
number = int(raw_input()) #通过 raw_input()输入的数字是字符串
#用 int()将该字符串转化为整数
if number == 10:
print "您输入的数字是:%d"%number
print "You are SMART."
elif number > 10:
print "您输入的数字是:%d"%number
print "This number is more than 10."
elif number < 10:
print "您输入的数字是:%d"%number
print "This number is less than 10."
else:
print "Are you a human?"
$ Python num.py
请输入任意一个整数数字:
您输入的数字是:12 This number is more than 10.
$ Python num.py
请输入任意一个整数数字:
您输入的数字是:10 You are SMART.
$ Python num.py
请输入任意一个整数数字:
您输入的数字是:9 This number is less than 10.
#! /usr/bin/env python
>>> name = "qiwsir" if "laoqi" else "github" >>> name 'qiwsir' >>> name = 'qiwsir' if "" else "python" >>> name 'Python' >>> name = "qiwsir" if "github" else "" >>> name 'qiwsir'
>>> x = 2 >>> y = 8 >>> a = "python" if x>y else "qiwsir" >>> a 'qiwsir' >>> b = "python" if x<y else "qiwsir" >>> b 'python'
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有