小白學python,迴圈案例購物介面

2021-10-07 02:59:05 字數 2587 閱讀 9698

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~~"

)

小白學Python(一)

小白學python 一 一 注釋 單行注釋 多行注釋 注 在python2中為了支援中文必須寫中文注釋在第一行 coding utf 8 二 定義變數 語法 變數名 變數值 例 a 10 在第一次為變數賦值為定義變數,第一次之後就為修改變數 變數的型別 1 數字 int 整型 long 長整型 fl...

小白學python 函式1

定義函式 def func print 我是乙個函式 print 函式結束了 呼叫函式 fucn 函式的引數和返回值def hello person print 你好呀!format person print 你看見我家aa了嗎?format person return none p 小v 呼叫函式...

Python小白基礎 迴圈語句

while迴圈的格式 while 條件 條件滿足時,做的事情1 條件滿足時,做的事情2 條件滿足時,做的事情3 省略 demo i 0 while i 5 print 當前是第 d次執行迴圈 i 1 print i d i i 1 while迴圈應用 1.計算1 100的累積和 包含1和100 2....