Day 14
到后面越来越难 每一课耗时也会越来越久 所以一定要把一课彻底学明白 不要着急赶进度 所以… 今天就这两课吧
Lesson 39
这一课学的是字典 也就是类似于告诉python Number里面有1, 2, 3, 4 然后等你找number的时候就会告诉你是1, 2, 3, 4 而4也是number里的
states = {
'Hubei':'HB',
'Anhui':'AH',
'Henan':'HN'
}
cities = {
'HB':'Wuhan',
'AH':'Hefei',
'HN':'Zhengzhou'
}
cities['AH'] = 'Fuyang'
cities['HN'] = 'Luoyang'
print('-'*10)
print("Hubei province has", cities['HB'])
print("Henan province has", cities['HN'])
print("Anhui province has", cities['AH'])
Lesson 40
这节课讲的是class emmm…的确很复杂 但是在下一节课会更详细的讲… 所以 我尽量明天把“面向对象”这课学明白 然后用自己的话写出来吧…
class Song(object):
def __init__(self, lyrics):
self.lyrics = lyrics
def sing_me_a_song(self):
for line in self.lyrics:
print(line)
happy_bday = Song(["Happy birthday to you",
"I don't want to get sued",
"So I'll stop right there"])
bulls_on_parade = Song(["They rally around tha family",
"With pockets full of shells"])
happy_bday.sing_me_a_song()
bulls_on_parade.sing_me_a_song()
今日进度
import sys
import time
def heartlost(heart) -> int:
heart -= 1
print("You lost one heart")
if heart == 0:
time.sleep(5)
print("You have ran out of heart, too bad! Game over.")
sys.exit()
else:
time.sleep(5)
print("Be careful! You only have %d heart left!" % heart)
return heart
def heartgain(heart):
heart += 1
print("You gain one heart!")
time.sleep(5)
print("You have %d heart now!" % heart)
return heart
def forest(heart):
print("You wake up and you find yourself in a dark dark forest.")
time.sleep(5)
print("You have two choices, 1. walk forward and try to find a road 2. try to find a flashlight")
time.sleep(5)
print("Please type 1 or 2:")
c = input('>')
if c == '1':
print("You can't see anything, you accidentally step on a snack, it bite you and ran away")
heart_now = heartlost(heart)
heart = heart_now
time.sleep(5)
print("You talk forward some more, and see a little house, you knock on the door")
house(heart)
if c == '2':
print("You knee down and try to see if there's anything on the ground, and, there's a flashlight!")
time.sleep(5)
print("You turn on the flashlight and see there's a little house in front")
time.sleep(5)
print("Will you knock on the door? 1. Yes 2. No")
c = input('>')
if c == '1':
house(heart)
else:
walk(heart)
def house(heart):
print("You peek through the window, the light is on")
time.sleep(5)
print("About a minute later, no one answer")
time.sleep(5)
print("Do you want to just open the door? 1. Yes, open it 2. No, I want to wait")
c = input('>')
if c == '1':
time.sleep(5)
print("There's someone behind the door, he yell at you and push you out of the house")
time.sleep(5)
print("You fell on the ground and hurt yourself")
heart_now = heartlost(heart)
heart = heart_now
walk(heart)
if c == '2':
time.sleep(5)
print("You wait another one minute, someone open the door, and ofer you some food")
time.sleep(5)
print("You eat it all and felt good!")
heart_now = heartgain(heart)
heart = heart_now
walk(heart)
def walk(heart):
print("You decide to walk forward")
forest(5)