注册 登录
编程论坛 Python论坛

一个关于中华人民共和国的小程序

风卷浪起 发布于 2021-11-28 11:39, 1661 次点击
class China:
    def __init__(self, cover, population):
        self.cover = cover
        self.population = population
        print(f"\tChina has about {self.cover} covers.")
        print(f"China has about {self.population} populations.")
        
    def moutains(self):
        print("\tChina has a lot of moutains.")
        
    def famous_moutain(self):
        print("Mount Huang is famous.")
        
    def rivers(self):
        print("\tChina has a lot of rivers, too.")
        
    def famous_river(self):
        print("And Huanghe river, Yangze river is famous, too.")
        
    def love_China(self):
        print("\tI love China!")
        
the_China = China(9600000, 1400000000)
the_China.moutains()
the_China.famous_moutain()
the_China.rivers()
the_China.famous_river()
the_China.love_China()

这是我无聊时写的一个小程序,欢迎大家点评(运行时无错误)!比如可以简化一些部分吗?

[此贴子已经被作者于2023-10-1 22:50编辑过]

4 回复
#2
风卷浪起2022-01-18 20:11
还有一个版本:
class China:
    def __init__(self):
        print("\tChina is so great!")
        
    def coverpollution(self, cover, population):   
        self.cover = cover
        self.population = population
        print(f"\tChina has about {self.cover} covers. ", end = '')
        print(f"China has about {self.population} populations.")
        
    def moutains(self):
        print("\tChina has a lot of moutains.")
        
    def famous_moutain(self):
        print("Mount Huang is famous.")
        
    def rivers(self):
        print("\tChina has a lot of rivers, too.")
        
    def famous_river(self):
        print("And Huanghe river, Yangze river is famous, too.")
        
    def love_China(self):
        print("\tI love China!")
        
the_China = China()
the_China.coverpollution(9600000,1400000000)
the_China.moutains()
the_China.famous_moutain()
the_China.rivers()
the_China.famous_river()
the_China.love_China()

[此贴子已经被作者于2023-10-1 22:53编辑过]

#3
储备2022-01-23 08:32
#4
风卷浪起2022-02-06 12:15
怎么样?
#5
sssooosss2022-03-04 18:41
共同进步
1