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. python 决策树

    RID age income student credit_rating Class:buys_computer 1 youth high no fair no 2 youth high no exc ...

  2. 大数据入门到精通17--union all 和disctinct 的用法

    一.union all 的用法.使用union all 或者 unionselect * from rental where rental_id <10union allselect * fro ...

  3. c#Socket Tcp服务端编程

    创建一个socket服务类,绑定监听端口, 然后创建一个线程listen连接的客户端, 把监听到的客户端加入dictionary里面,以便于管理, 同时创建receive线程,循环接收数据加入list ...

  4. 修改Windows server 时间同步

    1.关闭“与Internet时间同步”选项. 2.禁用Windows时间服务,并将其设置为手动. 3.禁用Hyper-v时间同步服务,并将其设置为手动,这个在Hyper-v软件上选中要修改的虚拟机,设 ...

  5. mysql in 子查询 效率慢,对比

    desc SELECT id,detail,groupId from hs_knowledge_point where groupId in ( UNION all ) UNION ALL SELEC ...

  6. JSP(介绍,语法,指令)

    什么是JSP JSP全名为Java Server Pages,java服务器页面.JSP是一种基于文本的程序,其特点就是HTML和Java代码共同存在! JSP的工作原理 其实JSP在第一次被访问的时 ...

  7. 2018-2019-20175302实验二《Java面向对象程序设计》实验报告

    2018-2019-2 学号实验二<Java面向对象程序设计>实验报告 一.实验步骤及内容 1. 面向对象程序设计 参考 http://www.cnblogs.com/rocedu/p/6 ...

  8. intelliJ idea如何安装、配置

    https://www.cnblogs.com/jajian/p/7989032.html

  9. C#编码问题以及C#往Mysql插数据编码问题

    C#将字符转换成utf8编码 GB321编码转换   public static string get_uft8(string unicodeString) { UTF8Encoding utf8 = ...

  10. 2. 2A03简介

    2A03简介 1.CPU 1.1 内部寄存器 1.累加寄存器A(Accumulator):8位寄存器,用于同算术逻辑单元(ALU)共同完成各种算术逻辑运算,它既为ALU提供原始操作数又担任存放ALU运 ...