I noticed that Japanese variable names can be used now, so I tried to see how much I could write in Japanese.
# -*- coding: utf-8 -*-
from magic import*
#Make products for sale
price list=dictionary()
price list["Apple"] = 100
price list["Mandarin orange"] = 50
price list["melon"] = 200
Purchase history=list()
#Make a purchase history appropriately
for number of times in serial number list(10):
Product name list=price list.Get all the names()
Product name number=Get a random number(0,length(Product name list) - 1)
Purchase history.Stick(list(商品名list)[Product name number])
display("=====Purchase history=====")
for number of times,Purchased items in count(Purchase history):
display("%dth time:%s" % (Number of times+ 1,Purchased item))
#Calculate total payment
Total payment= 0
for Purchased Items in Purchase History:
Total payment+=price list[Purchased item]
display("=====Total payment=====")
display(Total payment)
=====Purchase history=====
First time:Mandarin orange
Second time:melon
Third time:Apple
4th:melon
5th time:melon
6th time:Mandarin orange
7th time:Mandarin orange
8th time:Mandarin orange
9th time:Mandarin orange
10th time:melon
=====Total payment=====
1150
Magic for writing programs in Japanese
Magic.py
# -*- coding: utf-8 -*-
import builtins
import random
_builtin_list = builtins.list
_builtin_dict = builtins.dict
#List replacement class definition
class list(_builtin_list):
Stick= _builtin_list.append
Stick the list together= _builtin_list.extend
Put in= _builtin_list.insert
Erase=Kesu= _builtin_list.remove
Take out=Take out= _builtin_list.pop
Erase everything=Erase everything= _builtin_list.clear
look for=Search= _builtin_list.index
count=Count= _builtin_list.count
Line up=Line up= _builtin_list.sort
Arrange upside down=Arrange upside down= _builtin_list.reverse
copy= _builtin_list.copy
#Dictionary replacement class definition
class dictionary(_builtin_dict):
Get all names and content=Get all the names= _builtin_dict.items
Get all the names=Get all the names= _builtin_dict.keys
Get all the contents=Get it all= _builtin_dict.values
Erase everything=Erase everything= _builtin_dict.clear
copy= _builtin_dict.copy
get= _builtin_dict.get
Take out=Take out= _builtin_dict.pop
Pop out name and content=Extract name and content= _builtin_dict.popitem
Incorporate=Incorporate= _builtin_dict.setdefault
Combine=To be sick= _builtin_dict.update
#Built-in function alias definition
display=Hyouji= print
length=Length= len
Get a random number=Get a random kazu= random.randint
Get a random decimal=Get a random shosou= random.random
Serial number list=Goodwill list= range
Count=I'll give you= enumerate
dictionary=Jisho
#Built-in object replacement
builtins.list =list
builtins.dict =Jisho
def __test():
#Problem verification code
data_list = list()
data_list=list()
data_Comprehension list= []
print(["data_list", type(data_list)])
print(["data_list", type(data_list)])
print(["data_Comprehension list", type(data_Comprehension list)])
"""
output
['data_list', <class '__main__.list'>]
['data_list', <class '__main__.list'>]
['data_Comprehension list', <class 'list'>]
Unfortunately there is a problem that the list of comprehensions cannot be replaced
"""
if __name__ == "__main__":
__test()
It's a pity that the included List and Dict classes can't be replaced as I'm trying with __test ()
.
Recommended Posts