學習了一點簡單語法,感覺可以做個東西啦~。
寫了乙個簡單的****:買寵物!活學活用,自己學的語法知識結合了一點幽默的氣質。
#author: zachary_li
#**購物系統
while true:
maxslary = input("請輸入您準備消費的最大資產值:\n")
if maxslary.isdigit() == true:
if int(maxslary) > 0:
break
else:
print("*輸入資金錯誤!*")
maxslary = int(maxslary)
commodity = [["貓",100,5],["狗",60,5],["鳥",80,5]]
commoditylen = len(commodity)
'''for i in range(0,commoditylen):
print( i+1,".",commodity[i][0],"\t",commodity[i][1],"元")
'''#選擇自己想要的的商品
while true:
print("你的資產剩餘:", maxslary, "元")
print("----------------------------")
print("所有商品列表:")
for i in range(0,commoditylen):
print("no.1", commodity[i][0], "\t", "單價:",commodity[i][1],"元\t","剩餘",commodity[i][2],"只")
choicex = input("請輸入購買寵物的號數(退出輸入q):")
if choicex == 'q':
print("**退出系統成功,歡迎再次光臨!**")
break
elif choicex == '1':
if commodity[0][1] > maxslary:
print('**大爺,錢不夠呀**')
continue
elif commodity[0][2] <= 0:
print("sorry,本店沒有貓了")
continue
else:
maxslary = maxslary - commodity[0][1]
commodity[0][2] = commodity[0][2] - 1
print("大爺,成功購買乙隻貓!")
elif choicex == '2':
if commodity[1][1] > maxslary:
print('**大爺,錢不夠呀**')
continue
elif commodity[1][2] <= 0:
print("sorry,本店沒有狗了")
continue
else:
maxslary = maxslary - commodity[1][1]
commodity[1][2] = commodity[1][2] - 1
print("大爺,成功購買乙隻狗!")
elif choicex == '3':
if commodity[2][1] > maxslary:
print('**大爺,錢不夠呀**')
continue
elif commodity[2][2] <= 0:
print("sorry,本店沒有鳥了")
continue
else:
maxslary = maxslary - commodity[2][1]
commodity[2][2] = commodity[2][2] - 1
print("大爺,成功購買乙隻鳥!")
else:
print("**輸入寵物號數錯誤,請從新輸入!**")
print("您購買了。。。")
很認真的寫完,感覺挺好玩的,不論哪一種程式語言想要熟練一定是經常使用,不用過兩天也就忘了。
給自己的要求,不求記憶,但求理解,程式語言多不勝數,程式設計思想卻是可以共同。
Python實現桌面寵物
基於pyqt5 import os import cfg import sys import random from pyqt5.qtgui import from pyqt5.qtcore import from pyqt5.qtwidgets import from pyqt5 import q...
我的寵物狗之python實戰
class dog 小狗狗 definit self,name,age 初始化屬性name和age.self.name name self.age age defwang self 模擬狗狗汪汪叫.print self.name.title 汪汪 defshen self 模擬狗狗伸舌頭.print...
Python之斷言及示例
assert 斷言語句用來宣告某個條件是真的,其作用是測試乙個條件是否成立,如果不成立,則跑出異常。1 assertequal self,first,second,msg none 判斷兩個引數相等 first second 2 assertnotequal self,first,second,ms...