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. Django启动报错笔记

    NO.1: You have 15 unapplied migration(s). Your project may not work properly until you apply the mig ...

  2. PTA变成总结1

    1)实验代码 #include<stdio.h>int main(){ int N,k,n,i,j,p,m,ge; char op; while(1){  scanf("%d % ...

  3. mongodb安装使用简单命令

    .window+x,A,管理员进入cmd.cd C:\Program Files\MongoDB\Server\3.4\bin.安装:mongod --dbpath "D:\work\DB\ ...

  4. docker学习-常用命令2

    三.容器管理命令3.1 Docker commit 命令,从容器创建一个新的镜像.OPTIONS说明: -a :提交的镜像作者: -c :使用Dockerfile指令来创建镜像: -m :提交时的说明 ...

  5. 接口测试之——Charles抓包及常见问题解决(转载自https://www.jianshu.com/p/831c0114179f)

    简介 Charles其实是一款代理服务器,通过成为电脑或者浏览器的代理,然后截取请求和请求结果达到分析抓包的目的.该软件是用Java写的,能够在Windows,Mac,Linux上使用,安装Charl ...

  6. 【spring】使用spring过程中踩到的坑

    这里简单记录一下,学习spring的时候碰过的异常: 异常:org.springframework.beans.factory.BeanDefinitionStoreException: Unexpe ...

  7. centos 7.4安装zabbix 3

    1.安装前准备 1)关闭防火墙 systemctl status firewalld #查看防火墙状态 systemctl stop firewalld.service #停止firewall sys ...

  8. PHP+Mysql 实现数据库增删改查(原生)

    Mysql数据库创建 创建一个新闻列表的数据库: 1. 查询数据库 1.1. 创建文件dbconfig.php,保存常量 <?php define("HOST"," ...

  9. CentOS7升级默认内核

    安装内核升级镜像源 rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm Yum安装内核 yum --e ...

  10. win10修改TXT文件的关联软件

    打开注册表,按下面路径找: HKEY_CLASSES_ROOT -> txtfile -> shell -> open -> command 在右边可以看到一个默认文件,原来的 ...