-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Student(): | ||
def __init__(self,name,age,score): | ||
self.name=name | ||
self.age=age | ||
self.score=score | ||
|
||
def get_name(self): | ||
print(self.name) | ||
|
||
def get_age(self): | ||
print(self.age) | ||
|
||
def get_course(self): | ||
print(max(self.score)) | ||
|
||
a = Student('代恒',18,[105,104,123]) | ||
a.get_name() | ||
a.get_age() | ||
a.get_course() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import random | ||
class Person(): | ||
def __init__(self,name): | ||
self.name=name | ||
self.score=0 | ||
|
||
def fingerPlay(self): | ||
game=['石头','剪刀','布'] | ||
index=random.randint(0,2) | ||
return game[index] | ||
|
||
class Game(): | ||
def __init__(self,number,aname,bname): | ||
self.number=number | ||
self.a=Person(aname) | ||
self.b=Person(bname) | ||
|
||
def playGame(self): | ||
for i in range(self.number): | ||
a_out=self.a.fingerPlay() | ||
b_out=self.b.fingerPlay() | ||
|
||
if a_out==b_out: | ||
print('双方平局,出的是{}'.format(a_out)) | ||
elif (a_out=='石头' and b_out=='剪刀') or (a_out=='布' and b_out=='石头') or (a_out=='剪刀' and b_out=='布'): | ||
self.a.score+=1 | ||
print('{}获得胜利,出的是{},{}出的是{}'.format(self.a.name,a_out,self.b.name,b_out)) | ||
else: | ||
self.b.score+=1 | ||
print('{}获得胜利,出的是{},{}出的是{}'.format(self.b.name,b_out,self.a.name,a_out)) | ||
if self.a.score>self.b.score: | ||
print('恭喜{}获得游戏胜利,得分{}'.format(self.a.name,self.a.score)) | ||
elif self.a.score<self.b.score: | ||
print('恭喜{}获得游戏胜利,得分{}'.format(self.b.name,self.b.score)) | ||
else: | ||
print('双方平局,不分胜负') | ||
|
||
one=Game(5,'D','Y') | ||
one.playGame() |