1.3if判断语句+while和for循环语句+购物车作业
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循环语句+购物车作业的更多相关文章
- 分支语句 if的嵌套 循环语句
0930 今天学习内容做以下总结: 语句的分类:顺序语句,分支语句(选择,条件),循环语句 分支语句 格式1:if(表达式(要么是true 要么是false)){} 格式2:if(){}slse{} ...
- Go条件语句、switch和循环语句
一:Go条件语句 package main import "fmt" //========go条件判断语句=== func main() { { fmt.Println(" ...
- switch语句以及三种循环语句的总结
1:switch语句(1)格式:switch(表达式) {case 值1:语句体1;break;case 值2:语句体2;break;...default:语句体n+1;break;} 格式解释说明: ...
- java基础3 循环语句:While 循环语句、do while 循环语句、 for 循环语句 和 break、continue关键字
一.While循环语句 1.格式 while(条件表达式){ 执行语句: } 2.要点 1,先判断后执行 2,循环次数不定 3,避免死循环 3.举例 题目1:输出0-100之间的所有数 class D ...
- Golang基础(2):Go条件语句、switch和循环语句
一:Go条件语句 package main import "fmt" //========go条件判断语句=== func main() { { fmt.Println(" ...
- Python条件判断和循环语句
一.条件判断语句 通过一条或多条语句的判断来决定是否执行代码块 1.if语句基本形式: if 判断条件: 语句块 例如: score=75if score>=60: print &q ...
- 【python之路4】循环语句之while
1.while 循环语句 #!/usr/bin/env python # -*- coding:utf-8 -*- import time bol = True while bol: print '1 ...
- python之最强王者(3)——变量,条件、循环语句
1.Python 变量类型 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中. 因此,变量可以指定不同的 ...
- javascript语句——条件语句、循环语句和跳转语句
× 目录 [1]条件语句 [2]循环语句 [3]跳转语句 前面的话 默认情况下,javascript解释器依照语句的编写顺序依次执行.而javascript中的很多语句可以改变语句的默认执行顺序.本文 ...
随机推荐
- canel的网络策略
资源: https://docs.projectcalico.org/v3.2/getting-started/kubernetes/installation/flannel 基于pod Egress ...
- Codeforces Round #491 (Div. 2)
Codeforces Round #491 (Div. 2) https://codeforces.com/contest/991 A #include<bits/stdc++.h> us ...
- vue 存取、设置、清除cookie
步骤: 第一步:assets目录下添加cookie.js文件 export function setCookie(c_name,value,expire) { var date=new Date() ...
- ELK-Elasticsearch 安装启动
系统版本:Centos7 Elasticsearch:5.3.1 1:关闭SELinux [root@es local]# sed -i 's/SELINUX=enforcing/SELINUX=di ...
- 有关Lambda的一些思考
问题: What do lambda expressions do? Can we write all functions as lambda expressions? In what cases a ...
- django settings配置文件ALLOWED_HOSTS
ALLOWED_HOSTS列表为了防止黑客入侵,只允许列表中的ip地址访问 填写上“*”可以使所有的网址都能访问Django项目了,项目测试的时候,可以这么做.这样就失去了保护
- Spring bean的生命流程
Spring 是一个轻量级的 J2EE 开源框架,其目标是降低企业级应用开发难度,提高企业级应用开发效率.在日程开发中,我们会经常使用 Spring 框架去构建应用.所以作为一个经常使用的框架,了解其 ...
- node 单个表加条件查询
export const getTeacher = query => { const wh = model.query(qb => { qb.where('isNoLectur ...
- python_appium_模拟器启动app进行登录
#coding=utf-8from appium import webdriverimport timedesired_caps = {} #列表desired_caps['platformName' ...
- MAC使用超级终端
其实很简单. 先用ls看看/dev/tty.*哪个是具体的串口,我这里使用的edison的板子,所以插到macos上后可以看到的设备节点为: 只需要使用screen 命令即可,具体的命令格式如下: s ...