A game until you enter a quest-like adventure in python's interactive mode. It helped me to understand the basics of python because it holds the basic syntax of python.
I couldn't put the gif video, so I added music to the video and uploaded it to youtube.
** ・ input method ** Can be entered by the user at the console. Store the entered value in a variable.
** ・ if statement ** Conditional branch
** ・ while statement ** Loop until "yes" is entered
** ・ Dictionary type array ** Variable = {'key 1': value 1,'key 2': value 2, ...} Save the value with a name (key). Since the order is random, specify the key when extracting.
** ・ for statement ** Used to retrieve the contents of an array one by one. If the array is dictionary type, the keys will be extracted one by one.
** · try except syntax ** Describes the processing when an error occurs. except KeyError: An error that occurs when you enter a key that does not exist in the dictionary array.
** ・ print function ** Output a string to the console. Connect variables and strings with +. Convert the numerical value to a character string (str).
** ・ str function ** Convert a number to a string.
** ・ format function ** One of variable expansion. Print variables in the print function. You can use either the method of specifying the values in the order of the array number or the method of specifying the values with a name.
** ・ f character string ** One of variable expansion. Print variables in the print function. Easy to write and easy to use.
start = input('Make an adventure (yes or no):')
if start=='Yes':
start=1
else:
start=0
while start==0:
start = input('Make an adventure (yes or no):')
if start=='Yes':
start=1
else:
start=0
print('--------------------------------------------------\n')
name = input('Please enter your name:')
print('--------------------------------------------------\n')
print('Good morning'+name+'.. It's already Asa.\n')
print('Today is very important.\n'+name+'But for the first time, it was a fold.\n')
print('First of all, prepare the sobi.')
print('--------------------------------------------------\n')
start = input('Look at Genzai's Shojikin (yes or no):')
if start=='Yes':
start=1
else:
start=0
while start==0:
start = input('Look at Genzai's Shojikin (yes or no):')
if start=='Yes':
start=1
else:
start=0
money=5000
print('--------------------------------------------------\n')
print('Genzai no Shojikin'+str(money)+'It's gold.\n')
sords={'Hinoki cypress':300, 'Seido sword':1200, 'Hagane sword':2000, 'Yusha's sword':4600}
shields={'Pan lid':400, 'Mahou no Tate':1480, 'Fire':1800, 'Yusha no Tate':4600}
armors={'Kawa armor':500, 'Dangerous swimsuit':1370, 'Dragon mail':1910, 'Yusha armor':4600}
helmets={'Kawanoboshi':520, 'Usamimi Band':1420, 'Happiness':1840, 'Yusha's helmet':4600}
buysord="None"
buyshield="None"
buyarmor="None"
buyhelmet="None"
#Weapon purchase
print('--------------------------------------------------\n')
start = input('Look at the weapon (yes or no):')
if start=='Yes':
for sord in sords:
print('・'+sord+':'+str(sords[sord])+'gold')
print('--------------------------------------------------\n')
err=0
while err==0:
buysord = input('Which weapon do you want:')
try:
price=sords[buysord]
err=1
except KeyError:
err=0
if money >= price:
print('\n'+str(price)+'Gold'+buysord+'I bought it.')
money -= price
print('Shojikin'+str(money)+'It's gold.')
else:
print('\n I don't have enough.')
print('I didn't have a weapon.\n')
print('Shojikin'+str(money)+'It's gold.')
#Buy a shield
print('--------------------------------------------------\n')
start = input('Look at the vertical (yes or no):')
if start=='Yes':
for shield in shields:
print (f'・{shield}:{shields[shield]}gold')
print('--------------------------------------------------\n')
err=0
while err==0:
buyshield = input('Which one do you want?')
try:
price=shields[buyshield]
err=1
except KeyError:
err=0
if money >= price:
print(f'\n{price}Gold{buyshield}I bought it.' )
money -= price
print(f'Shojikin{money}It's gold.')
else:
print('\n I don't have enough.')
print('It wasn't fresh.\n')
print(f'Shojikin{money}It's gold.')
#Buy armor
print('--------------------------------------------------\n')
start = input('Look at the armor (yes or no):')
if start=='Yes':
for armor in armors:
print('・'+armor+':'+str(armors[armor])+'gold')
print('--------------------------------------------------\n')
err=0
while err==0:
buyarmor = input('Which armor do you want:')
try:
price=armors[buyarmor]
err=1
except KeyError:
err=0
if money >= price:
print('\n{price}Gold{buyarmor}I bought it.'.format(price=price, buyarmor=buyarmor) )
money -= price
print('Shojikin{money}It's gold.'.format(money=money))
else:
print('\n I don't have enough.')
print('There was no armor.\n')
print('Shojikin{money}It's gold.'.format(money=money))
#Purchasing a helmet
print('--------------------------------------------------\n')
start = input('Look at the helmet (yes or no):')
if start=='Yes':
for helmet in helmets:
print(f'・{helmet}:{helmets[helmet]}gold')
print('--------------------------------------------------\n')
err=0
while err==0:
buyhelmet = input('Which helmet do you wear:')
try:
price=helmets[buyhelmet]
err=1
except KeyError:
err=0
if money >= price:
print('\n{}Gold{}I bought it.'.format(price, buyhelmet) )
money -= price
print('Shojikin{kane}It's gold.'.format(kane=money))
else:
print('\n I don't have enough.')
print('There was no armor.\n')
print('--------------------------------------------------\n')
print('Sobi no Konyu is over.\n\n')
print('★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★')
print(f'\n<{name}Sobi>')
print(f'・ Weapon:{buysord}')
print(f'・ Vertical:{buyshield}')
print(f'・ Armor:{buyarmor}')
print(f'・ Kabuto:{buyhelmet}\n')
print('★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★ ★')
print('\n\n Please do your best.\n')
print('end\n\n')
Recommended Posts