1、if 语句

if userame=_usename and password=_password:

print("welcome user {name} login...").fomat(name=username)

elif userame=_usename and password!=_password:

print("hello user {name} ,your password is wrong!").fomat(name=username)

else:

print("invalid username and password!")

#换行为python的功能表示子代码(即次级代码)

2、while循环语句

while True:

break                         #跳出循环

pass                          #什么都不做

else:

3、for循环语句

for i in range(0,10,3):    #i从0开始循环10次,隔3个开始一次

continue                        #直接下一循环

break                            #跳出循环

else:                              #for正常走完了之后执行(即没中途break)

4、购物车作业

购物车功能说明:输入工资,显示商品,输入商品编号购买商品

product_list=[
("book",100),
("coffee",50),
("table",200),
("shit",10),
("computer",10000)
]
shop_list=[]
shop_money=0 while True:
salary = input("input your salary>>>")
if salary.isdigit():
salary = int(salary)
break
else:
print("you must input number!") while True:
if salary == 0:
print("your money left 0 yuan,break")
break
if shop_list != []:
print("the goods you have picked:%s"%shop_list)
print("your salary balance %d yuan." % salary)
for goods in enumerate(product_list):
print(goods)
num=input("what do you want to bug?(you can input 0-4,or \"q\" to quit)")
if num.isdigit():
num = int(num)
if num >=0 and num <=4:
price = product_list[num]
if price[1] <= salary:
salary -=price[1]
shop_list.append(price[0])
shop_money +=price[1]
else:
print("you have no much money!") else:
print("input wrong digit!") elif num=="q":
break else:
print("input wrong digit!") print("the goods you have picked:%s"%shop_list)
print("it will cost you {cost} yuan,and your salary will balance {yuan} yuan".format(cost=shop_money,yuan=salary))

1.3if判断语句+while和for循环语句+购物车作业的更多相关文章

  1. 分支语句 if的嵌套 循环语句

    0930 今天学习内容做以下总结: 语句的分类:顺序语句,分支语句(选择,条件),循环语句 分支语句 格式1:if(表达式(要么是true 要么是false)){} 格式2:if(){}slse{}  ...

  2. Go条件语句、switch和循环语句

    一:Go条件语句 package main import "fmt" //========go条件判断语句=== func main() { { fmt.Println(" ...

  3. switch语句以及三种循环语句的总结

    1:switch语句(1)格式:switch(表达式) {case 值1:语句体1;break;case 值2:语句体2;break;...default:语句体n+1;break;} 格式解释说明: ...

  4. java基础3 循环语句:While 循环语句、do while 循环语句、 for 循环语句 和 break、continue关键字

    一.While循环语句 1.格式 while(条件表达式){ 执行语句: } 2.要点 1,先判断后执行 2,循环次数不定 3,避免死循环 3.举例 题目1:输出0-100之间的所有数 class D ...

  5. Golang基础(2):Go条件语句、switch和循环语句

    一:Go条件语句 package main import "fmt" //========go条件判断语句=== func main() { { fmt.Println(" ...

  6. Python条件判断和循环语句

    一.条件判断语句 通过一条或多条语句的判断来决定是否执行代码块 1.if语句基本形式: if 判断条件:    语句块 例如: score=75if score>=60:    print &q ...

  7. 【python之路4】循环语句之while

    1.while 循环语句 #!/usr/bin/env python # -*- coding:utf-8 -*- import time bol = True while bol: print '1 ...

  8. python之最强王者(3)——变量,条件、循环语句

    1.Python 变量类型 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中. 因此,变量可以指定不同的 ...

  9. javascript语句——条件语句、循环语句和跳转语句

    × 目录 [1]条件语句 [2]循环语句 [3]跳转语句 前面的话 默认情况下,javascript解释器依照语句的编写顺序依次执行.而javascript中的很多语句可以改变语句的默认执行顺序.本文 ...

随机推荐

  1. Mysql 常用操作记录

    1.查看数据库: mysql> show databases; +--------------------+ | Database | +--------------------+ | info ...

  2. 记一次yii2 上传文件

    1 view渲染 <form action="../src/website/import/report-flow" method="post" encty ...

  3. innodb_flush_log_at_trx_commit与sync_binlog理解

    innodb_flush_log_at_trx_commit该参数控制重做日志写入磁盘的过程.我们知道 InnoDB 使用“Write Ahead Log”策略来避免数据丢失问题,即依靠重做日志来保证 ...

  4. LAB7 REST

    r需要初始化才能赋值. 不要盲目抄doGet方法,要理解题目的意思

  5. maven之如何将自己的写的 maven 构件发布到 nexus 私服

    概念:Nexus服务器是一个代码包管理的服务器,可以理解 Nexus 服务器是一个巨大的 Library 仓库.Nexus 可以支持管理的工具包括 Maven , npm 等,对于 JAVA 开发来说 ...

  6. SUBMIT WITHOUT ALV

    data:seltab type table of rsparams, seltab_wa like line of seltab. define add_seltab. if &1 is n ...

  7. python日志

    日志 -- 用来记录用户行为或者代码的执行过程 logging.debug('debug message') # 低级别的 # 排错信息 logging.info('info message') # ...

  8. 第5-7次OO作业总结分析

    (1)从多线程的协同和同步控制方面,分析和总结自己三次作业来的设计策略及其变化. 第五次作业 第五次作业是对多线程的初步探索,所以对于多线程的基本书写机制的认识比较多.本次作业难点在于了解多线程的运作 ...

  9. 为nginx创建windows服务自启动

    1.下载最新版的 Windows Service Wrapper 程序,比如我下载的名称是 "winsw-1.9-bin.exe",然后,把它命名成你想要的名字(比如: " ...

  10. [JavaScript] 弹出编辑框

    效果:单击图片copy,双击图片或者点Edit都会打开编辑窗口 Style <style> .black_overlay{ display: none; position: absolut ...