if语句的练习代码

判断进网吧:
a = int(input('请输入你的出生年份:'))
# b = int(input('请输入今年是那一年'))
b = 2018
age =b  - a
print('你的年龄是:%d'%age)
if age >= 18:
    print('你可以进入网吧')
else:
    print('自己多大心里没点B数吗\n未满18周岁,禁止入内')
判断星期:

a = int(input('please input a num:'))
if a == 1:
    print('MON')
elif a==2:
    print('TUES')
elif a == 3:
    print('WEN')
elif a == 4:
    print('THURS')
elif a == 5:
    print('FIR')
elif a == 6:
    print('SAT')
elif a == 7:
    print('SUN')
 
 
#1: 石头 2:剪刀 3: 布
# 需求 让用户输入一个值   将输入转化成int
# 判断:用户赢--  用户输入1   电脑出2
                # 用户输入2   电脑出3
                # 用户输入3 电脑出1
         #平局  用户输入 ==  电脑
         #否则   就是电脑获胜

user =int(input('please input a num:'))
computer = 1
if (user == 1 and computer  == 2) or (user==2 and computer ==3 )or (user ==3 and computer == 1):
    print('you  win')
elif user == computer :
    print('peace')
else:
    print('you lose')
石头剪刀布晋级:
 
 
import  random
user = int(input('请猜拳  1:石头\t2:剪刀\t3:布:'))
computer = random.randint (1,3)
if user >3:
    print('输入有误')
else:
    if (user == 1 and computer ==2) or (user == 2 and computer == 3)\
            or (user == 3 and computer == 1):
        print('恭喜你赢了,不要走决战到天亮')
    elif user == computer :
        print('平局')
    else:
        print('道行太浅回家练练')

猜你喜欢

转载自blog.csdn.net/Fantasy_worm/article/details/80290559