Study 5 —— 流程控制

if 条件:
  满足条件后要执行的代码
else:
  if条件不满足就执行这里

#_*_coding:utf-8_*_
---------------------------------------------------	
#单分支
username = 'Lisa'
password = '123'
Username = input('Input your name: ')
Password = input('Input your password: ')

if Username == username and Password == password :
  print('Welcome to the system!')
else :
  print('The username or password is not right!')
---------------------------------------------------
#双分支
Name = input('Input your name: ')
Sex = input('Input your sex: ')
Age = int(input('Input your age: '))

if Sex == 'girl' :
  if Age < 18 :
    print('She is a little princess!')
  else :
    print('She is going to marry!')
else :
  print('No one likes him!')
---------------------------------------------------
#多分支
(1)
age = 26

user_guess = int(input('Input a number you guess: '))

if user_guess == age :
  print('You are right!')
elif user_guess > age :
  print('Try smaller!')
else :
  print('Try bigger!')

(2)#根据成绩不同,给予不同等级
Score = int(input('Input Score: '))

if Score <= 100 :
  if Score >= 90 : 
    print('A')
  elif Score >= 80 :
    print('B')
  elif Score >= 60 :
    print('C')
  elif Score >= 40 :
    print('D')
  elif Score >= 0 :
    print('E')
  else :
    print('You are a fool!')
else :
  print('Must be less than 100!')

  

转载于:https://www.cnblogs.com/vurtne-lu/p/7799145.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值