小白学python,循环案例购物界面

import sys
while True:
	print('\t\t\t 商店登录界面\n')
	print("\t\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n")
	print("\t\t\t 1、用户登录\n")
	print("\t\t\t 2、用户注册\n")
	print("\t\t\t 3、退出系统\n")
	print("\t\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n")
	choice = input('请输入您的选择:')

	if choice == "1":
	#用户需要登录
		username = input("请输入你的用户名称:")
		password = input("请输入您的用户密码:")

		if username == "admin" and password == "1":
			#用户登陆成功、
			while True:
				print('\t\t\t 商城首页\n')
				print("\t\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n")
				print("\t\t\t 1、进入购物超市\n")
				print("\t\t\t 2、休闲小游戏\n")
				print("\t\t\t 3、返回上一层\n")
				print("\t\t\t 4、退出系统\n")
				print("\t\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n")
				choice = input('请输入您的选择:')
				if choice == "1":
					#商城

					while True:
						print('\t\t\t 商城首页\n')
						print("\t\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n")
						print("\t\t\t 编号    名称      价格    库存")
						print("\t\t\t  1     避孕套      32¥    12\n")
						print("\t\t\t  2     可口可乐     3¥    32\n")
						print("\t\t\t  3、返回上一层\n")
						print("\t\t\t  4、退出系统\n")
						print("\t\t ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*\n")
						choice = input('请输入您的选择:')
						#判断购买那个商品
						if choice == "1":
							amount = int(input("请输入购买数量:"))
							price = 32
							count = amount * price
							print("购买结果是:%s"%(amount * price))
						elif choice == "2":
							amount = int(input("请输入购买数量:"))
							price = 3
							count = amount * price
							print("购买结果是:%s"%(amount * price))
						elif choice == "3":
							#放回上一侧
							break
						elif choice == "4":
							#退出程序
								sys.exit()


				elif choice == "2":
					print("小游戏")
				elif choice == "3":
					#放回上一侧
					break
				elif choice == "4":
					#退出程序
					sys.exit()

		else:
			input("用户名称或者密码错误,请重新登录,按任意键结束")
		
	elif choice == "2":
	#用户需要注册
	# pass是python的关键字,这段代码目前忽略不计
		pass
	elif choice == "3":
	#退出系统
		break

		print("game over~~")
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python中的循环是编程中最常用的结构之一。有两种类型的循环:while循环和for循环。在本文中,我们将专注于while循环并提供了20个实用的示例帮助您习和理解while循环的基本概念和用法。下面是其中一个示例: Example 1: 简单的while循环 ``` i = 1 while i <= 5: print(i) i += 1 ``` 该示例中,我们使用了一个简单的while循环来打印出1到5的数字。循环首先初始化变量`i`为1,然后打印出`i`的值,并将`i`增加1。这个过程会继续重复,直到`i`的值大于5为止。 另一个示例是使用while循环计算阶乘: Example 5: 使用while循环计算阶乘 ``` n = 5 factorial = 1 while n > 0: factorial *= n n -= 1 print("5的阶乘是:", factorial) ``` 在这个示例中,我们使用while循环计算了5的阶乘。我们首先初始化变量`n`为5并将`factorial`设置为1。然后,我们在循环中将`n`乘以`factorial`并将`n`减1。这个过程会一直重复,直到`n`的值减少到0为止。最后,我们打印出计算得到的阶乘结果。 这些示例展示了while循环Python中的基本使用方法。通过实践这些示例,您可以更好地理解和掌握while循环的概念,并将其应用到您的编程实践中。希望这些案例对您Python编程有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Python教程: while循环20例](https://blog.csdn.net/weixin_46121540/article/details/129235403)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值