backup: 2025-03-05
This commit is contained in:
parent
df8fc9d4a0
commit
c3e445fd2c
|
@ -1,30 +0,0 @@
|
|||
import requests
|
||||
import re
|
||||
|
||||
def translate(text, target_language):
|
||||
url = 'https://translate.google.cn/_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&f.sid=-2984828793698248690&bl=boq_translate-webserver_20201221.17_p0&hl=zh-CN&soc-app=1&soc-platform=1&soc-device=1&_reqid=5445720&rt=c'
|
||||
headers = {
|
||||
'origin': 'https://translate.google.cn',
|
||||
'referer': 'https://translate.google.cn/',
|
||||
'sec-fetch-dest': 'empty',
|
||||
'sec-fetch-mode': 'cors',
|
||||
'sec-fetch-site': 'same-origin',
|
||||
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36',
|
||||
'x-client-data': 'CIW2yQEIpbbJAQjEtskBCKmdygEIrMfKAQj2x8oBCPfHygEItMvKAQihz8oBCNzVygEIi5nLAQjBnMsB',
|
||||
'Decoded':'message ClientVariations {repeated int32 variation_id = [3300101, 3300133, 3300164, 3313321, 3318700, 3318774, 3318775, 3319220, 3319713, 3320540, 3329163, 3329601];}',
|
||||
'x-same-domain': '1'
|
||||
}
|
||||
data = {'f.req': f'[[["MkEWBc","[[\\"{text}\\",\\"auto\\",\\"{target_language}\\",true],[null]]",null,"generic"]]]'}
|
||||
res = requests.post(url, headers=headers, data=data).text
|
||||
temp = re.findall(r'\\(.*?)\\', res)
|
||||
index = temp.index('"zh')
|
||||
yiwen=str(temp[index-1]).replace('"','')
|
||||
return yiwen
|
||||
|
||||
if __name__ == '__main__':
|
||||
text = input("请输入你要翻译的内容:")
|
||||
|
||||
if len(text) > 0:
|
||||
print('译文:' + translate(text, "zh"))
|
||||
else:
|
||||
print("非法输入,无结果")
|
|
@ -1,3 +0,0 @@
|
|||
.idea/
|
||||
.vscode/
|
||||
__pycache__/
|
|
@ -1,31 +0,0 @@
|
|||
# File: Dice.py
|
||||
# Description: Dice Class
|
||||
# Author: ZiTing Wang
|
||||
# Student ID: 2218040103
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
import random
|
||||
|
||||
class Dice:
|
||||
diceStrings = {
|
||||
1: '⚀',
|
||||
2: '⚁',
|
||||
3: '⚂',
|
||||
4: '⚃',
|
||||
5: '⚄',
|
||||
6: '⚅'
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.point = 0
|
||||
|
||||
def roll(self):
|
||||
self.point = random.randint(1, 7)
|
||||
|
||||
def getPointOfDice(self, power: int) -> tuple[int | int, str]:
|
||||
self.roll()
|
||||
currentPoint = self.point + power
|
||||
if currentPoint > 6:
|
||||
currentPoint = currentPoint % 6
|
||||
return currentPoint, self.diceStrings[currentPoint]
|
|
@ -1,454 +0,0 @@
|
|||
# File: GameBase.py
|
||||
# Description: GameBase class and three game classes
|
||||
# Author: ZiTing Wang
|
||||
# Student ID: 2218040103
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
|
||||
from Dice import Dice
|
||||
from Player import Player
|
||||
|
||||
|
||||
class GameBase:
|
||||
inputPrompt = "> "
|
||||
coinsOfPlayers = {}
|
||||
playerBids = {}
|
||||
allPlayers = {}
|
||||
def __init__(self):
|
||||
self.__helpMsg = '\nWhat would you like to do?\n(n) register a new player\n(c) show your coinsNum\n(s) show ' \
|
||||
'the leader board\n(p) play a game\n(q) quit'
|
||||
self.__acceptableOptions = ['n', 'c', 's', 'p', 'q']
|
||||
|
||||
def newPlayer(self) -> None:
|
||||
"""
|
||||
New a player
|
||||
:return: None
|
||||
"""
|
||||
print("What is the name of the new player?")
|
||||
name = input(self.inputPrompt)
|
||||
if name in self.allPlayers:
|
||||
print("Sorry, the name is already taken.")
|
||||
else:
|
||||
self.allPlayers[name] = Player(name)
|
||||
print("Welcome, ", name)
|
||||
|
||||
def printLeaderBoard(self):
|
||||
try:
|
||||
if len(self.allPlayers) == 0:
|
||||
raise ValueError
|
||||
for player in self.allPlayers:
|
||||
self.coinsOfPlayers[player] = self.allPlayers[player].getCoinNum()
|
||||
leaderBoard = sorted(self.coinsOfPlayers.items(), key=lambda k: k[1], reverse=True)
|
||||
print("=============================")
|
||||
print("Name\t\tPlayed\tWon\tCoins")
|
||||
print("=============================")
|
||||
for player in leaderBoard:
|
||||
name = player[0]
|
||||
coinsNum = player[1]
|
||||
print(
|
||||
f"{name}\t\t"
|
||||
f"{self.allPlayers[name].total_round}"
|
||||
f"\t{self.allPlayers[name].win_round}"
|
||||
f"\t{coinsNum}")
|
||||
print("=============================")
|
||||
except ValueError:
|
||||
print("You have no player now!")
|
||||
|
||||
def queryCoinsNum(self):
|
||||
try:
|
||||
if len(self.allPlayers) == 0:
|
||||
raise ValueError
|
||||
print("=============================")
|
||||
for player in self.allPlayers:
|
||||
print(f"{player}\t\t"
|
||||
f"{self.allPlayers[player].getCoinNum()}")
|
||||
except ValueError:
|
||||
print("No player now!")
|
||||
|
||||
def startGame(self):
|
||||
print('Which game would you like to play?\n'
|
||||
'(e) Even-or-Odd\n'
|
||||
'(m) Minz\n'
|
||||
'(b) Bunco')
|
||||
game = input(self.inputPrompt)
|
||||
if game not in ['e', 'm', 'b']:
|
||||
print("Invalid choice!")
|
||||
else:
|
||||
self.callGameRun(game)
|
||||
|
||||
def processInputOptions(self, op: str) -> None:
|
||||
if op == 'n':
|
||||
self.newPlayer()
|
||||
elif op == 's':
|
||||
self.printLeaderBoard()
|
||||
elif op == 'c':
|
||||
self.queryCoinsNum()
|
||||
elif op == 'p':
|
||||
self.startGame()
|
||||
else:
|
||||
raise ValueError
|
||||
|
||||
def addPlayerToGame(self, minNum, maxNum):
|
||||
"""
|
||||
Add a player
|
||||
:param minNum:
|
||||
:param maxNum:
|
||||
:return:
|
||||
"""
|
||||
print(f"How many players ({minNum}-{maxNum})?")
|
||||
try:
|
||||
numsPlayer = int(input(self.inputPrompt))
|
||||
if numsPlayer < minNum or numsPlayer > maxNum:
|
||||
raise ValueError
|
||||
for i in range(numsPlayer):
|
||||
while True:
|
||||
print(f"What is the name of player #{i + 1}?")
|
||||
name = input(self.inputPrompt)
|
||||
if name not in self.allPlayers:
|
||||
print(f'There is no player named {name}.')
|
||||
elif name in self.playerBids:
|
||||
print(f'{name} is already in the game.')
|
||||
else:
|
||||
while True:
|
||||
print(
|
||||
f"How many coins would you bid {name} (1-{self.allPlayers[name].getCoinNum()})?")
|
||||
try:
|
||||
coinBids = int(input(self.inputPrompt))
|
||||
if coinBids > self.allPlayers[name].getCoinNum() or coinBids < 1:
|
||||
raise ValueError
|
||||
else:
|
||||
self.playerBids[name] = coinBids
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid number of coins.")
|
||||
break
|
||||
except ValueError:
|
||||
print(f"Please input a number between {minNum} and {maxNum}!")
|
||||
self.addPlayerToGame(minNum, maxNum)
|
||||
|
||||
def playGame(self):
|
||||
"""
|
||||
Start a game
|
||||
:return:
|
||||
"""
|
||||
while True:
|
||||
print(self.__helpMsg)
|
||||
op = input(self.inputPrompt)
|
||||
try:
|
||||
self.processInputOptions(op)
|
||||
except ValueError:
|
||||
print("Sorry! Please retry with a valid command.")
|
||||
|
||||
def callGameRun(self, gameOp: str) -> None:
|
||||
"""
|
||||
Choose game
|
||||
:param gameOp:
|
||||
"""
|
||||
if gameOp == 'e':
|
||||
game = EvenOrOdd(self.allPlayers)
|
||||
game.playGame()
|
||||
elif gameOp == 'm':
|
||||
game = Minz(self.allPlayers)
|
||||
game.playGame()
|
||||
elif gameOp == 'b':
|
||||
game = Bunco(self.allPlayers)
|
||||
game.playGame()
|
||||
|
||||
|
||||
class EvenOrOdd(GameBase):
|
||||
def __init__(self, players):
|
||||
super().__init__()
|
||||
self.__persons = 0
|
||||
self.allPlayers = players
|
||||
self.player = ""
|
||||
|
||||
def playGame(self):
|
||||
if len(self.allPlayers) < 1:
|
||||
print("No enough players to play EvenOrOdd!")
|
||||
return
|
||||
dice = Dice()
|
||||
print("Let's play the game of EvenOrOdd!")
|
||||
self.choice = ''
|
||||
self.power = ''
|
||||
print(f"Hey {self.player}, Even (e) or Odd (o)?")
|
||||
while True:
|
||||
self.choice = input(self.inputPrompt)
|
||||
if self.choice not in ('e', 'o'):
|
||||
print("Invalid choice.")
|
||||
print("Even (e) or Odd (o)?")
|
||||
else:
|
||||
break
|
||||
while True:
|
||||
print("How strong will you throw (0-5)?")
|
||||
try:
|
||||
self.power = int(input(self.inputPrompt))
|
||||
if self.power > 5 or self.power < 0:
|
||||
raise ValueError
|
||||
else:
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid choice.")
|
||||
point = dice.getPointOfDice(self.power)
|
||||
result = self.getGuessResult(self.choice, point[0])
|
||||
print(point[1])
|
||||
if result:
|
||||
print(f"Congratulations, {self.player}! You win!")
|
||||
self.allPlayers[self.player].win(self.playerBids[self.player])
|
||||
self.allPlayers[self.player].win_round += 1
|
||||
self.allPlayers[self.player].total_round += 1
|
||||
else:
|
||||
print(f"Sorry, {self.player}! You lose!")
|
||||
self.allPlayers[self.player].fail(self.playerBids[self.player])
|
||||
self.allPlayers[self.player].total_round += 1
|
||||
|
||||
def addPlayerToGame(self, minNum, maxNum):
|
||||
"""
|
||||
Add a player
|
||||
:param minNum:
|
||||
:param maxNum:
|
||||
:return:
|
||||
"""
|
||||
while True:
|
||||
print("What is the name of player?")
|
||||
self.player = input(self.inputPrompt)
|
||||
if self.player not in self.allPlayers:
|
||||
print(f'There is no player named {self.player}.')
|
||||
else:
|
||||
while True:
|
||||
print(
|
||||
f"How many coinsNum would you bid {self.player} (1-{self.allPlayers[self.player].getCoinNum()})?")
|
||||
try:
|
||||
input_coin = int(input(self.inputPrompt))
|
||||
if input_coin > self.allPlayers[self.player].getCoinNum() or input_coin < 1:
|
||||
raise ValueError
|
||||
else:
|
||||
self.playerBids[self.player] = input_coin
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid number of coinsNum.")
|
||||
break
|
||||
|
||||
def getGuessResult(self, choice: str, point: int) -> bool:
|
||||
"""
|
||||
Judge the result :return:bool
|
||||
"""
|
||||
isEven = not (point % 2)
|
||||
if choice == 'e' and isEven:
|
||||
return True
|
||||
elif choice == 'o' and isEven:
|
||||
return False
|
||||
elif choice == 'e' and not isEven:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class Minz(GameBase):
|
||||
points = {}
|
||||
additionalTurnPlayers = []
|
||||
|
||||
def __init__(self, players):
|
||||
super().__init__()
|
||||
self.__persons = 0
|
||||
self.allPlayers = players
|
||||
|
||||
def playGame(self):
|
||||
if len(self.allPlayers) < 3:
|
||||
print("No enough players to play Minz!")
|
||||
return
|
||||
print("Let the game begin!")
|
||||
self.addPlayerToGame(3, 5)
|
||||
self.play1Turn()
|
||||
if len(self.additionalTurnPlayers):
|
||||
self.playAdditionalTurn()
|
||||
sorted(self.points.items(), key=lambda d: d[1])
|
||||
print("-----RESULT-----")
|
||||
for point in self.points:
|
||||
print(point, self.points[point])
|
||||
print("")
|
||||
winner = max(self.points.items(), key=lambda d: d[1])
|
||||
winner = winner[0]
|
||||
for key in self.points:
|
||||
if key == winner:
|
||||
self.allPlayers[key].win(self.playerBids[key])
|
||||
self.allPlayers[key].win_round += 1
|
||||
self.allPlayers[key].total_round += 1
|
||||
else:
|
||||
self.allPlayers[key].fail(self.playerBids[key])
|
||||
self.allPlayers[key].total_round += 1
|
||||
print(f"Congratulations, {winner}! You win!")
|
||||
|
||||
def play1Turn(self):
|
||||
reversed = {}
|
||||
self.play1Round(self.playerBids)
|
||||
for key, value in self.points.items():
|
||||
if value not in reversed:
|
||||
reversed[value] = [key]
|
||||
else:
|
||||
reversed[value].append(key)
|
||||
reversed = sorted(reversed)
|
||||
for key in reversed:
|
||||
if len(reversed[key]) > 1:
|
||||
self.additionalTurnPlayers = reversed[max(reversed, key=lambda k: k[1])]
|
||||
break
|
||||
|
||||
def playAdditionalTurn(self):
|
||||
self.play1Round(self.additionalTurnPlayers)
|
||||
|
||||
def play1Round(self, players):
|
||||
dice = Dice()
|
||||
for key in players:
|
||||
choice = ''
|
||||
self.power = ''
|
||||
print(f"It's {key}'s turn.")
|
||||
self.points[key] = 0
|
||||
while True:
|
||||
print("How strong will you throw (0-5)?")
|
||||
try:
|
||||
self.power = int(input(self.inputPrompt))
|
||||
if self.power > 5 or self.power < 0:
|
||||
raise ValueError
|
||||
else:
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid choice.")
|
||||
for i in range(2):
|
||||
point = dice.getPointOfDice(self.power)
|
||||
print(point[1], end=" ")
|
||||
self.points[key] += point[0]
|
||||
print("")
|
||||
|
||||
|
||||
class Bunco(GameBase):
|
||||
def __init__(self, players: dict):
|
||||
super().__init__()
|
||||
self.currentPlayer = None
|
||||
self.__persons = 0
|
||||
self.allPlayers = players
|
||||
self.playerNum = len(self.playerBids)
|
||||
self.playerName = [i for i in self.allPlayers]
|
||||
self.totalScores = {}
|
||||
self.roundWinners = []
|
||||
self.buncos = {}
|
||||
|
||||
def playGame(self):
|
||||
if len(self.allPlayers) < 2:
|
||||
print("No enough players to play Bunco!")
|
||||
return
|
||||
self.addPlayerToGame(2, 4)
|
||||
for i in self.allPlayers:
|
||||
self.totalScores[i] = []
|
||||
for i in self.playerBids:
|
||||
self.buncos[i] = 0
|
||||
print("Let's play the game of Bunco!")
|
||||
startingPlayer = self.playerName[0]
|
||||
for roundNum in range(1, 7):
|
||||
self.play1Round(roundNum, startingPlayer)
|
||||
self.printResults()
|
||||
|
||||
def play1Round(self, roundNum, starting_player):
|
||||
print(f"<Round {roundNum}>")
|
||||
self.currentPlayer = starting_player
|
||||
round_scores = {}
|
||||
while True:
|
||||
for player in self.playerName:
|
||||
current_total = 0
|
||||
self.totalScores[player].append(0)
|
||||
print(f"It's {player}'s turn.")
|
||||
roll = self.getResult()
|
||||
points = self.calculateScore(roll, roundNum)
|
||||
current_total += points
|
||||
print(f"You earned {points} points, {current_total} points in total.")
|
||||
while points > 0:
|
||||
self.totalScores[player][roundNum - 1] += points
|
||||
current_total += points
|
||||
if self.totalScores[player][roundNum - 1] >= 21:
|
||||
round_scores[player] = current_total
|
||||
break
|
||||
print(f"Keep playing {player}.")
|
||||
roll = self.getResult()
|
||||
points = self.calculateScore(roll, roundNum)
|
||||
current_total += points
|
||||
print(f"You earned {points} points, {current_total} points in total.")
|
||||
round_scores[player] = current_total
|
||||
round_winner = (max(round_scores.items(), key=lambda k: k[1]))[0]
|
||||
print(f"{round_winner} is the winner in round {roundNum}!\n")
|
||||
self.roundWinners.append(round_winner)
|
||||
return
|
||||
|
||||
def getResult(self) -> list:
|
||||
dice = Dice()
|
||||
self.power = 0
|
||||
while True:
|
||||
print("How strong will you throw (0-5)?")
|
||||
try:
|
||||
self.power = int(input(self.inputPrompt))
|
||||
if self.power > 5 or self.power < 0:
|
||||
raise ValueError
|
||||
else:
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid choice.")
|
||||
points = []
|
||||
for i in range(3):
|
||||
point = dice.getPointOfDice(self.power)
|
||||
print(point[1], end=" ")
|
||||
points.append(point[0])
|
||||
print("")
|
||||
return points
|
||||
|
||||
def printResults(self):
|
||||
roundNum = 1
|
||||
print("==================================")
|
||||
print("Round", end='\t')
|
||||
for player in self.playerBids:
|
||||
print(player, end='\t')
|
||||
print("")
|
||||
for player in range(6):
|
||||
print(f"\t{roundNum}\t", end="")
|
||||
for player in self.totalScores:
|
||||
print(f"{self.totalScores[player][roundNum - 1]}\t", end="")
|
||||
print("")
|
||||
roundNum += 1
|
||||
print("==================================")
|
||||
print("Total\t", end="")
|
||||
for player in self.playerName:
|
||||
print(f"{sum(self.totalScores[player])}\t", end="")
|
||||
print("")
|
||||
print("==================================")
|
||||
print("Bunco\t", end="")
|
||||
for player in self.playerName:
|
||||
print(f'{self.buncos[player]}\t', end="")
|
||||
print("")
|
||||
numWins = {}
|
||||
for player in self.playerName:
|
||||
numWins[player] = 0
|
||||
for player in self.roundWinners:
|
||||
numWins[player] += 1
|
||||
winner = max(numWins.items(), key=lambda k: k[1])[0]
|
||||
print(
|
||||
f'{winner} won {numWins[winner]} rounds, scoring {sum(self.totalScores[winner])} points, with {self.buncos[winner]} Buncos')
|
||||
print(f'Congratulations, {winner}! You win!')
|
||||
for player in self.playerName:
|
||||
if player == winner:
|
||||
self.allPlayers[player].win(self.playerBids[player])
|
||||
self.allPlayers[player].win_round += 1
|
||||
self.allPlayers[player].total_round += 1
|
||||
else:
|
||||
self.allPlayers[player].fail(self.playerBids[player])
|
||||
self.allPlayers[player].total_round += 1
|
||||
|
||||
def calculateScore(self, roll: list[int], round_number):
|
||||
score = 0
|
||||
point = roll[0]
|
||||
if roll[0] == roll[1] == roll[2]:
|
||||
if point == round_number:
|
||||
score += 21
|
||||
self.buncos[self.currentPlayer] += 1
|
||||
else:
|
||||
score += 5
|
||||
for point in roll:
|
||||
if point == round_number:
|
||||
score += 1
|
||||
return score
|
|
@ -1,25 +0,0 @@
|
|||
# File: Player.py
|
||||
# Description: Player Class
|
||||
# Author: ZiTing Wang
|
||||
# Student ID: 2218040103
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
class Player:
|
||||
def __init__(self, name):
|
||||
self.__name = name
|
||||
self.win_round = 0
|
||||
self.total_round = 0
|
||||
self.__numOfCoins = 100
|
||||
|
||||
def addCoins(self, coinsNum):
|
||||
self.__numOfCoins += coinsNum
|
||||
|
||||
def win(self, coinsNum):
|
||||
self.addCoins(coinsNum)
|
||||
|
||||
def fail(self, coinsNum):
|
||||
self.addCoins(-coinsNum)
|
||||
|
||||
def getCoinNum(self):
|
||||
return self.__numOfCoins
|
|
@ -1,18 +0,0 @@
|
|||
# File: TonsODice.py
|
||||
# Description: TonsODice Class
|
||||
# Author: ZiTing Wang
|
||||
# Student ID: 2218040103
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
from GameBase import GameBase
|
||||
|
||||
|
||||
class TonsODice:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
print('Welcome to Tons-o-Dice!\nDeveloped by ZiTing Wang\nCOMP 1048 Object-Oriented Programming')
|
||||
game = GameBase()
|
||||
game.playGame()
|
|
@ -1,13 +0,0 @@
|
|||
#
|
||||
# File: main.py
|
||||
# Description: The mainn entrance of the whole program
|
||||
# Author: ZiTing Wang
|
||||
# Student ID: 2218040103
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
from TonsODice import TonsODice
|
||||
|
||||
if __name__ == '__main__':
|
||||
tod = TonsODice()
|
||||
tod.run()
|
|
@ -1,27 +0,0 @@
|
|||
import random
|
||||
import unittest
|
||||
from Dice import Dice
|
||||
from GameBase import EvenOrOdd
|
||||
from Player import Player
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def testPlayer(self):
|
||||
player = Player("Yiting")
|
||||
assert(player.getCoinNum(), 100)
|
||||
def testDiceRollResult(self):
|
||||
dice = Dice()
|
||||
for i in range(1000):
|
||||
point = (dice.getPointOfDice(random.randint(0, 5)))[0]
|
||||
assert (1 <= point <= 6, True)
|
||||
|
||||
def testResultOfEvenOrOdd(self):
|
||||
game = EvenOrOdd({})
|
||||
assert (game.getGuessResult('o', 4), False)
|
||||
assert (game.getGuessResult('o', 3), True)
|
||||
assert (game.getGuessResult('e', 4), True)
|
||||
assert (game.getGuessResult('e', 3), False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -1,75 +0,0 @@
|
|||
<diagram program="umletino" version="15.1"><zoom_level>11</zoom_level><help_text>Space for diagram not</help_text><element><id>UMLClass</id><coordinates><x>341</x><y>0</y><w>176</w><h>187</h></coordinates><panel_attributes>Player
|
||||
-
|
||||
name:str
|
||||
--numOfcCoin:int
|
||||
--numOfGameWon:int
|
||||
--totalRound:int
|
||||
-
|
||||
+play()
|
||||
+choose()
|
||||
+bid()
|
||||
+odd_or_even()
|
||||
</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>220</x><y>341</y><w>187</w><h>99</h></coordinates><panel_attributes>TonsODice
|
||||
--
|
||||
+run()</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>0</x><y>913</y><w>165</w><h>209</h></coordinates><panel_attributes>EvenOrOdd
|
||||
--
|
||||
-player: str
|
||||
--
|
||||
+addPlayerToGame()
|
||||
+getGuessResult()
|
||||
+playGame()</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>550</x><y>341</y><w>143</w><h>99</h></coordinates><panel_attributes>Dice
|
||||
--
|
||||
--diceStrings: dict
|
||||
--
|
||||
+roll()
|
||||
+getPointOfDice()</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>231</x><y>913</y><w>154</w><h>209</h></coordinates><panel_attributes>Minz
|
||||
-
|
||||
-points: dict
|
||||
-additionalTurnPlayers: list
|
||||
--
|
||||
+playGame()
|
||||
+play1Round()
|
||||
+play1Turn()
|
||||
+playAdditionalTurn()
|
||||
</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>429</x><y>913</y><w>176</w><h>209</h></coordinates><panel_attributes>Bunco
|
||||
-
|
||||
-playerNum: int
|
||||
-playerName: list
|
||||
-totalScores: dict
|
||||
-roundWinners: list
|
||||
-buncosL dict
|
||||
-
|
||||
+playGame()
|
||||
+calculateScore()
|
||||
+getResult()
|
||||
+play1Round()
|
||||
+printResults()</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>66</x><y>759</y><w>209</w><h>176</h></coordinates><panel_attributes>lt=<<-
|
||||
m1=1
|
||||
m2=1</panel_attributes><additional_attributes>170;10;10;140</additional_attributes></element><element><id>Relation</id><coordinates><x>297</x><y>759</y><w>44</w><h>176</h></coordinates><panel_attributes>lt=<<-
|
||||
m1=1
|
||||
m2=1</panel_attributes><additional_attributes>10;10;10;140</additional_attributes></element><element><id>Relation</id><coordinates><x>363</x><y>759</y><w>154</w><h>176</h></coordinates><panel_attributes>lt=<<-
|
||||
m1=1
|
||||
m2=1</panel_attributes><additional_attributes>10;10;120;140</additional_attributes></element><element><id>Relation</id><coordinates><x>396</x><y>363</y><w>176</w><h>44</h></coordinates><panel_attributes>lt=<<<<<-
|
||||
m1=1
|
||||
m2=1...n</panel_attributes><additional_attributes>10;10;140;10</additional_attributes></element><element><id>Relation</id><coordinates><x>297</x><y>176</y><w>165</w><h>187</h></coordinates><panel_attributes>lt=<<<<-
|
||||
m1=1...n
|
||||
m2=1</panel_attributes><additional_attributes>120;10;10;150</additional_attributes></element><element><id>Relation</id><coordinates><x>429</x><y>176</y><w>220</w><h>187</h></coordinates><panel_attributes>lt=<-
|
||||
m1=1...n
|
||||
m2=1</panel_attributes><additional_attributes>10;10;180;150</additional_attributes></element><element><id>UMLNote</id><coordinates><x>572</x><y>583</y><w>154</w><h>77</h></coordinates><panel_attributes>ZiTing Wang
|
||||
2218040103</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>220</x><y>528</y><w>187</w><h>242</h></coordinates><panel_attributes>GameBase
|
||||
--
|
||||
-inputPrompt: str
|
||||
-coinsOfPlayers: dict
|
||||
-playerBids: dict
|
||||
-allPlayers: dict
|
||||
--
|
||||
+newPlayer()
|
||||
+playGame()
|
||||
+callGameRun()
|
||||
+addPlayerToGame()
|
||||
+printLeaderBoard()
|
||||
+queryCoinsNum()
|
||||
+startGame()
|
||||
+processInputOptions()</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>297</x><y>429</y><w>44</w><h>121</h></coordinates><panel_attributes>lt=-
|
||||
m1=1
|
||||
m2=1</panel_attributes><additional_attributes>10;10;10;90</additional_attributes></element></diagram>
|
|
@ -1,2 +0,0 @@
|
|||
.idea/
|
||||
__pycache__/
|
|
@ -1,33 +0,0 @@
|
|||
# File: Dice.py
|
||||
# Description: Dice Class
|
||||
# Author: Yirui Guo
|
||||
# Student ID: 2218040201
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
import random
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
class Dice:
|
||||
symbols = {
|
||||
1: '⚀',
|
||||
2: '⚁',
|
||||
3: '⚂',
|
||||
4: '⚃',
|
||||
5: '⚄',
|
||||
6: '⚅'
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.point = 0
|
||||
|
||||
def roll(self):
|
||||
self.point = random.randint(1, 7)
|
||||
|
||||
def get_point_of_dice(self, power: int) -> tuple[int | int, str]:
|
||||
self.roll()
|
||||
point = self.point + power
|
||||
if point > 6:
|
||||
point = point % 6
|
||||
return point, self.symbols[point]
|
414
M3101/2/Game.py
414
M3101/2/Game.py
|
@ -1,414 +0,0 @@
|
|||
# File: Game.py
|
||||
# Description: Game class and three game classes
|
||||
# Author: Yirui Guo
|
||||
# Student ID: 2218040201
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
from Dice import Dice
|
||||
from Player import Player
|
||||
|
||||
|
||||
class Game:
|
||||
players = {}
|
||||
bids = {}
|
||||
|
||||
def __init__(self):
|
||||
self.prompt = "> "
|
||||
self.__valid_inputs = ['n', 'c', 's', 'p', 'q']
|
||||
self.__helpMsg = '\nWhat would you like to do?\n(n) register a new player\n(c) show your coins\n(s) show the leader board\n(p) play a game\n(q) quit'
|
||||
|
||||
def handle_game(self, comm):
|
||||
if comm == 'n':
|
||||
print("What is the name of the new player?")
|
||||
name = input(self.prompt)
|
||||
if name in self.players:
|
||||
print("Sorry, the name is already taken.")
|
||||
else:
|
||||
self.players[name] = Player(name)
|
||||
print("Welcome, ", name)
|
||||
elif comm == 'c':
|
||||
try:
|
||||
if len(self.players) == 0:
|
||||
raise AttributeError
|
||||
print("--------Coins--------")
|
||||
for key in self.players:
|
||||
print(key, self.players[key].get_coins())
|
||||
except AttributeError:
|
||||
print("You have no player now!")
|
||||
elif comm == 's':
|
||||
try:
|
||||
if len(self.players) == 0:
|
||||
raise AttributeError
|
||||
print("================================")
|
||||
print("Name\t\tPlayed\tWon\tCoins")
|
||||
print("================================")
|
||||
lb = {}
|
||||
for key in self.players:
|
||||
lb[key] = self.players[key].get_coins()
|
||||
top = sorted(lb.items(), key=lambda k: k[1], reverse=True)
|
||||
for key in top:
|
||||
print(f"{key[0]}\t\t{self.players[key[0]].total_round}\t{self.players[key[0]].win_round}\t{key[1]}")
|
||||
print("================================")
|
||||
except AttributeError:
|
||||
print("You have no player now!")
|
||||
elif comm == 'p':
|
||||
print('Which game would you like to play?\n(e) Even-or-Odd\n(m) Minz\n(b) Bunco')
|
||||
user_input = input(self.prompt)
|
||||
if user_input not in ['e', 'm', 'b']:
|
||||
print("Please choose from e, m, b!")
|
||||
else:
|
||||
self.call_game(user_input)
|
||||
else:
|
||||
raise ValueError
|
||||
|
||||
def set_persons(self, l, r):
|
||||
print(f"How many players ({l}-{r})?")
|
||||
try:
|
||||
user_input = int(input(self.prompt))
|
||||
if user_input < l or user_input > r:
|
||||
raise ValueError
|
||||
self.__persons = int(user_input)
|
||||
for i in range(self.__persons):
|
||||
while True:
|
||||
print(f"What is the name of player #{i + 1}?")
|
||||
user_input = input(self.prompt)
|
||||
if user_input not in self.players.keys():
|
||||
print(f'There is no player named {user_input}.')
|
||||
elif user_input in self.bids.keys():
|
||||
print(f'{user_input} is already in the game.')
|
||||
else:
|
||||
while True:
|
||||
print(
|
||||
f"How many coins would you bid {user_input} (1-{self.players[user_input].get_coins()})?")
|
||||
try:
|
||||
input_coin = int(input(self.prompt))
|
||||
if input_coin > self.players[user_input].get_coins() or input_coin < 1:
|
||||
raise ValueError
|
||||
else:
|
||||
self.bids[user_input] = input_coin
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid number of coins.")
|
||||
break
|
||||
except ValueError:
|
||||
print(f"Please input a number between {l} and {r}!")
|
||||
self.set_persons(l, r)
|
||||
|
||||
def play_game(self):
|
||||
while True:
|
||||
print(self.__helpMsg)
|
||||
user_input = input(self.prompt)
|
||||
try:
|
||||
self.handle_game(user_input)
|
||||
except ValueError:
|
||||
print("Sorry! Please retry with a valid command.")
|
||||
|
||||
def call_game(self, comm: str) -> None:
|
||||
"""
|
||||
Choose game
|
||||
:param comm:
|
||||
"""
|
||||
if comm == 'e':
|
||||
game = EvenOrOdd(self.players)
|
||||
game.play_game()
|
||||
elif comm == 'm':
|
||||
game = Minz(self.players)
|
||||
game.play_game()
|
||||
elif comm == 'b':
|
||||
game = Bunco(self.players)
|
||||
game.play_game()
|
||||
|
||||
|
||||
class Minz(Game):
|
||||
points = {}
|
||||
additional_turns_players = []
|
||||
|
||||
def __init__(self, players):
|
||||
super().__init__()
|
||||
self.__persons = 0
|
||||
self.players = players
|
||||
|
||||
def play_game(self):
|
||||
if len(self.players) < 3:
|
||||
print("No enough players to play EvenOrOdd!")
|
||||
return
|
||||
print("Let the game begin!")
|
||||
self.set_persons(3,5)
|
||||
self.the_first_turn()
|
||||
if len(self.additional_turns_players):
|
||||
self.the_second_turn()
|
||||
sorted(self.points.items(), key=lambda d: d[1])
|
||||
print("-----RESULT-----")
|
||||
for point in self.points:
|
||||
print(point, self.points[point])
|
||||
print("")
|
||||
winner = max(self.points.items(), key=lambda d: d[1])
|
||||
winner = winner[0]
|
||||
for key in self.points:
|
||||
if key == winner:
|
||||
self.players[key].win(self.bids[key])
|
||||
self.players[key].win_round += 1
|
||||
self.players[key].total_round += 1
|
||||
else:
|
||||
self.players[key].lose(self.bids[key])
|
||||
self.players[key].total_round += 1
|
||||
print(f"Congratulations, {winner}! You win!")
|
||||
|
||||
def the_first_turn(self):
|
||||
flipped = {}
|
||||
self.turn(self.bids)
|
||||
for key, value in self.points.items():
|
||||
if value not in flipped:
|
||||
flipped[value] = [key]
|
||||
else:
|
||||
flipped[value].append(key)
|
||||
flipped = sorted(flipped)
|
||||
for key in flipped:
|
||||
if len(flipped[key]) > 1:
|
||||
self.additional_turns_players = flipped[max(flipped, key=lambda k: k[1])]
|
||||
break
|
||||
|
||||
def the_second_turn(self):
|
||||
self.turn(self.additional_turns_players)
|
||||
|
||||
def turn(self, players):
|
||||
dice = Dice()
|
||||
for key in players:
|
||||
choice = ''
|
||||
self.power = ''
|
||||
print(f"It's {key}'s turn.")
|
||||
self.points[key] = 0
|
||||
while True:
|
||||
print("How strong will you throw (0-5)?")
|
||||
try:
|
||||
self.power = int(input(self.prompt))
|
||||
if self.power > 5 or self.power < 0:
|
||||
raise ValueError
|
||||
else:
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid choice.")
|
||||
for i in range(2):
|
||||
point = dice.get_point_of_dice(self.power)
|
||||
print(point[1], end=" ")
|
||||
self.points[key] += point[0]
|
||||
print("")
|
||||
|
||||
|
||||
class EvenOrOdd(Game):
|
||||
def __init__(self, players):
|
||||
super().__init__()
|
||||
self.__persons = 0
|
||||
self.players = players
|
||||
self.player = ""
|
||||
|
||||
def play_game(self):
|
||||
if len(self.players) < 1:
|
||||
print("No enough players to play EvenOrOdd!")
|
||||
return
|
||||
dice = Dice()
|
||||
print("Let's play the game of EvenOrOdd!")
|
||||
while True:
|
||||
print("What is the name of player?")
|
||||
self.player = input(self.prompt)
|
||||
if self.player not in self.players:
|
||||
print(f'There is no player named {self.player}.')
|
||||
else:
|
||||
while True:
|
||||
print(
|
||||
f"How many coins would you bid {self.player} (1-{self.players[self.player].get_coins()})?")
|
||||
try:
|
||||
input_coin = int(input(self.prompt))
|
||||
if input_coin > self.players[self.player].get_coins() or input_coin < 1:
|
||||
raise ValueError
|
||||
else:
|
||||
self.bids[self.player] = input_coin
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid number of coins.")
|
||||
break
|
||||
choice = ''
|
||||
self.power = ''
|
||||
print(f"Hey {self.player}, Even (e) or Odd (o)?")
|
||||
while True:
|
||||
choice = input(self.prompt)
|
||||
if choice not in ('e', 'o'):
|
||||
print("Invalid choice.")
|
||||
print("Even (e) or Odd (o)?")
|
||||
else:
|
||||
break
|
||||
while True:
|
||||
print("How strong will you throw (0-5)?")
|
||||
try:
|
||||
self.power = int(input(self.prompt))
|
||||
if self.power > 5 or self.power < 0:
|
||||
raise ValueError
|
||||
else:
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid choice.")
|
||||
point = dice.get_point_of_dice(self.power)
|
||||
result = self.get_result(choice, point[0])
|
||||
print(point[1])
|
||||
if result:
|
||||
print(f"Congratulations, {self.player}! You win!")
|
||||
self.players[self.player].win(self.bids[self.player])
|
||||
self.players[self.player].win_round += 1
|
||||
self.players[self.player].total_round += 1
|
||||
else:
|
||||
print(f"Sorry, {self.player}! You lose!")
|
||||
self.players[self.player].lose(self.bids[self.player])
|
||||
self.players[self.player].total_round += 1
|
||||
|
||||
def get_result(self, choice: str, point: int) -> bool:
|
||||
is_even = not (point % 2)
|
||||
print(is_even)
|
||||
if choice == 'e' and is_even:
|
||||
return True
|
||||
elif choice == 'o' and is_even:
|
||||
return False
|
||||
elif choice == 'e' and not is_even:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
class Bunco(Game):
|
||||
def __init__(self, players: dict):
|
||||
super().__init__()
|
||||
self.current_player = None
|
||||
self.__persons = 0
|
||||
self.players = players
|
||||
self.set_persons(2, 4)
|
||||
self.num_players = len(self.bids)
|
||||
self.player_names = [i for i in self.players]
|
||||
self.scores = {}
|
||||
self.round_winners = []
|
||||
for _ in self.bids:
|
||||
self.scores[_] = []
|
||||
self.buncos = {}
|
||||
for _ in self.bids:
|
||||
self.buncos[_] = 0
|
||||
|
||||
def play_game(self):
|
||||
if len(self.players) < 2:
|
||||
print("No enough players to play EvenOrOdd!")
|
||||
return
|
||||
print("Let's play the game of Bunco!")
|
||||
starting_player = self.player_names[0]
|
||||
for round_number in range(1, 7):
|
||||
self.play_round(round_number, starting_player)
|
||||
self.print_results()
|
||||
|
||||
def play_round(self, round_number, starting_player):
|
||||
print(f"<Round {round_number}>")
|
||||
self.current_player = starting_player
|
||||
round_scores = {}
|
||||
while True:
|
||||
for player in self.player_names:
|
||||
current_total = 0
|
||||
self.scores[player].append(0)
|
||||
print(f"It's {player}'s turn.")
|
||||
roll = self.roll_dice()
|
||||
points = self.calc_score(roll, round_number)
|
||||
current_total += points
|
||||
print(f"You earned {points} points, {current_total} points in total.")
|
||||
while points > 0:
|
||||
self.scores[player][round_number - 1] += points
|
||||
current_total += points
|
||||
if self.scores[player][round_number - 1] >= 21:
|
||||
round_scores[player] = current_total
|
||||
break
|
||||
print(f"Keep playing {player}.")
|
||||
roll = self.roll_dice()
|
||||
points = self.calc_score(roll, round_number)
|
||||
current_total += points
|
||||
print(f"You earned {points} points, {current_total} points in total.")
|
||||
round_scores[player] = current_total
|
||||
round_winner = (max(round_scores.items(), key=lambda k: k[1]))[0]
|
||||
print(f"{round_winner} is the winner in round {round_number}!\n")
|
||||
self.round_winners.append(round_winner)
|
||||
return
|
||||
|
||||
def roll_dice(self) -> list:
|
||||
dice = Dice()
|
||||
self.power = 0
|
||||
while True:
|
||||
print("How strong will you throw (0-5)?")
|
||||
try:
|
||||
self.power = int(input(self.prompt))
|
||||
if self.power > 5 or self.power < 0:
|
||||
raise ValueError
|
||||
else:
|
||||
break
|
||||
except ValueError:
|
||||
print("Invalid choice.")
|
||||
points = []
|
||||
for i in range(3):
|
||||
point = dice.get_point_of_dice(self.power)
|
||||
print(point[1], end=" ")
|
||||
points.append(point[0])
|
||||
print("")
|
||||
return points
|
||||
|
||||
def print_results(self):
|
||||
print("======================================")
|
||||
print("Round", end='\t')
|
||||
for i in range(self.num_players):
|
||||
print(self.player_names[i], end='\t')
|
||||
print("")
|
||||
round_number = 1
|
||||
for i in range(6):
|
||||
print(f"\t{round_number}\t", end="")
|
||||
for key in self.scores:
|
||||
print(f"{self.scores[key][round_number - 1]}\t", end="")
|
||||
print("")
|
||||
round_number += 1
|
||||
print("======================================")
|
||||
print("Total\t", end="")
|
||||
for key in self.player_names:
|
||||
print(f"{sum(self.scores[key])}\t", end="")
|
||||
print("")
|
||||
print("======================================")
|
||||
print("Bunco\t", end="")
|
||||
for key in self.player_names:
|
||||
print(f'{self.buncos[key]}\t', end="")
|
||||
print("")
|
||||
round_wins = {}
|
||||
for i in self.player_names:
|
||||
round_wins[i] = 0
|
||||
for i in self.round_winners:
|
||||
round_wins[i] += 1
|
||||
winner = max(round_wins.items(), key=lambda k: k[1])[0]
|
||||
print(
|
||||
f'{winner} won {round_wins[winner]} rounds, scoring {sum(self.scores[winner])} points, with {self.buncos[winner]} Buncos')
|
||||
print(f'Congratrulations, {winner}! You win!')
|
||||
for i in self.player_names:
|
||||
if i == winner:
|
||||
self.players[i].win(self.bids[i])
|
||||
self.players[i].win_round += 1
|
||||
self.players[i].total_round += 1
|
||||
else:
|
||||
self.players[i].lose(self.bids[i])
|
||||
self.players[i].total_round += 1
|
||||
|
||||
|
||||
def calc_score(self, roll: list[int], round_number):
|
||||
score = 0
|
||||
point = roll[0]
|
||||
if roll[0] == roll[1] == roll[2]:
|
||||
if point == round_number:
|
||||
score += 21
|
||||
self.buncos[self.current_player] += 1
|
||||
else:
|
||||
score += 5
|
||||
for point in roll:
|
||||
if point == round_number:
|
||||
score += 1
|
||||
return score
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
game = Bunco({'a': Player('a'), 'b': Player('b')})
|
||||
game.play_game()
|
|
@ -1,25 +0,0 @@
|
|||
# File: Player.py
|
||||
# Description: Player Class
|
||||
# Author: Yirui Guo
|
||||
# Student ID: 2218040201
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
class Player:
|
||||
def __init__(self, name):
|
||||
self.__name = name
|
||||
self.__coin = 100
|
||||
self.win_round = 0
|
||||
self.total_round = 0
|
||||
|
||||
def add(self, coins):
|
||||
self.__coin += coins
|
||||
|
||||
def win(self, coins):
|
||||
self.add(coins)
|
||||
|
||||
def lose(self, coins):
|
||||
self.add(-coins)
|
||||
|
||||
def get_coins(self):
|
||||
return self.__coin
|
|
@ -1,68 +0,0 @@
|
|||
<diagram program="umletino" version="15.1"><zoom_level>10</zoom_level><help_text>Space for diagram notes</help_text><element><id>UMLClass</id><coordinates><x>70</x><y>650</y><w>100</w><h>150</h></coordinates><panel_attributes>Player
|
||||
-
|
||||
+name:str
|
||||
--coin:int
|
||||
--winRound:int
|
||||
|
||||
-
|
||||
+add()
|
||||
+win()
|
||||
+lost()
|
||||
+lose()
|
||||
+get_coins()</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>330</x><y>680</y><w>100</w><h>200</h></coordinates><panel_attributes>/Game/
|
||||
-
|
||||
+leaderBoard:list
|
||||
--numPeople:int
|
||||
--account:list
|
||||
--pond:int
|
||||
--bid:int
|
||||
#minPeople:int
|
||||
#maxPeople:int
|
||||
-
|
||||
+play_game()
|
||||
+handle_game()
|
||||
+set_persons()
|
||||
+call_game()</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>320</x><y>490</y><w>110</w><h>80</h></coordinates><panel_attributes>Dice
|
||||
-
|
||||
+point:str
|
||||
-
|
||||
+roll()
|
||||
+get_point_of_dice()
|
||||
</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>330</x><y>1010</y><w>100</w><h>140</h></coordinates><panel_attributes>Minz
|
||||
-
|
||||
-points: dict
|
||||
-additional_turns_players: list
|
||||
-
|
||||
+play_game()
|
||||
+the_first_turn()
|
||||
+the_second_turn()
|
||||
+turn()</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>160</x><y>1010</y><w>100</w><h>130</h></coordinates><panel_attributes>EvenOrOdd
|
||||
-
|
||||
|
||||
-
|
||||
+play_game()
|
||||
+get_result(): bool</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>490</x><y>990</y><w>170</w><h>190</h></coordinates><panel_attributes>Bunco
|
||||
-
|
||||
-current_player: str
|
||||
-num_players: int
|
||||
-player_names: list
|
||||
-scores: dict
|
||||
-round_winners: list
|
||||
-
|
||||
+play_game()
|
||||
+play_round()
|
||||
+rolll_dice()
|
||||
+print_results()
|
||||
+calc_score()</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>210</x><y>870</y><w>140</w><h>160</h></coordinates><panel_attributes>lt=<<-</panel_attributes><additional_attributes>120;10;10;140</additional_attributes></element><element><id>Relation</id><coordinates><x>370</x><y>870</y><w>30</w><h>160</h></coordinates><panel_attributes>lt=<<-</panel_attributes><additional_attributes>10;10;10;140</additional_attributes></element><element><id>Relation</id><coordinates><x>420</x><y>870</y><w>130</w><h>140</h></coordinates><panel_attributes>lt=<<-</panel_attributes><additional_attributes>10;10;110;120</additional_attributes></element><element><id>Relation</id><coordinates><x>160</x><y>710</y><w>190</w><h>50</h></coordinates><panel_attributes>lt=-
|
||||
m1=1...5
|
||||
m2=1
|
||||
play</panel_attributes><additional_attributes>10;20;170;20</additional_attributes></element><element><id>UMLNote</id><coordinates><x>740</x><y>520</y><w>160</w><h>70</h></coordinates><panel_attributes>Yirui Guo
|
||||
2218040201</panel_attributes><additional_attributes></additional_attributes></element><element><id>UMLClass</id><coordinates><x>580</x><y>700</y><w>100</w><h>90</h></coordinates><panel_attributes>TonsoDice
|
||||
-
|
||||
|
||||
-
|
||||
run()</panel_attributes><additional_attributes></additional_attributes></element><element><id>Relation</id><coordinates><x>420</x><y>730</y><w>180</w><h>40</h></coordinates><panel_attributes>lt=-
|
||||
</panel_attributes><additional_attributes>10;20;160;20</additional_attributes></element><element><id>Relation</id><coordinates><x>370</x><y>560</y><w>50</w><h>140</h></coordinates><panel_attributes>lt=-
|
||||
m1=1
|
||||
m2=1..3
|
||||
hold</panel_attributes><additional_attributes>10;120;10;10</additional_attributes></element></diagram>
|
|
@ -1,18 +0,0 @@
|
|||
# File: TonsODice.py
|
||||
# Description: TonsODice Class
|
||||
# Author: Yirui Guo
|
||||
# Student ID: 2218040201
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
from Game import Game
|
||||
|
||||
|
||||
class TonsODice:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
print('Welcome to Tons-o-Dice!\nDeveloped by Yirui Guo\nCOMP 1048 Object-Oriented Programming')
|
||||
game = Game()
|
||||
game.play_game()
|
|
@ -1,14 +0,0 @@
|
|||
#
|
||||
# File: main.py
|
||||
# Description: Main start point of my program
|
||||
# Author: Yirui Guo
|
||||
# Student ID: 2218040201
|
||||
# This is my own work as defined by
|
||||
# the University's Academic Misconduct Policy.
|
||||
#
|
||||
from Dice import Dice
|
||||
from TonsODice import TonsODice
|
||||
|
||||
if __name__ == '__main__':
|
||||
tod = TonsODice()
|
||||
tod.run()
|
|
@ -1,14 +0,0 @@
|
|||
import openai
|
||||
openai.api_base = "https://api.open.passingai.com"
|
||||
openai.api_key = "sk-L968sI6TYbd9XcwJ290aB121393148B39e86E1652f467f26"
|
||||
# print(openai.Model.list())
|
||||
|
||||
openai.ChatCompletion.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "You are a helpful assistant."},
|
||||
{"role": "user", "content": "Who won the world series in 2020?"},
|
||||
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
|
||||
{"role": "user", "content": "Where was it played?"}
|
||||
]
|
||||
)
|
|
@ -1,22 +0,0 @@
|
|||
import unittest
|
||||
|
||||
import Dice
|
||||
from Game import EvenOrOdd
|
||||
|
||||
|
||||
class MyTestCase(unittest.TestCase):
|
||||
def test_dice_roll(self):
|
||||
dice = Dice.Dice()
|
||||
point = dice.get_point_of_dice(3)
|
||||
assert 1 <= point[0] <= 6
|
||||
|
||||
def test_evenorodd_result(self):
|
||||
game = EvenOrOdd({})
|
||||
assert(game.get_result('o', 4), False)
|
||||
assert(game.get_result('o', 3), True)
|
||||
assert(game.get_result('e', 4), True)
|
||||
assert(game.get_result('e', 3), False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,C语言程序设计
|
||||
祝魏魏,男,4201806,94.4
|
||||
萧韩韩,女,4201815,94.4
|
||||
费谢蒋,女,4201823,94.4
|
||||
薛尤尤,女,4201831,94.4
|
||||
严屈尤,女,4201809,93.8
|
||||
葛喻计,男,4201856,93.6
|
||||
费襟计,男,4201843,93.3
|
||||
谢昌昌,女,4201822,92.9
|
||||
顾舒舒,女,4201835,92.8
|
||||
和苗宋,男,4201857,92.1
|
||||
汤邹邹,女,4201842,91.5
|
||||
陶韩韩,男,4201816,90.8
|
||||
舒米襟,男,4201817,90.7
|
||||
葛项项,男,4201830,90.6
|
||||
萧唐唐,男,4201838,90.5
|
||||
纪奚昌,男,4201849,90.5
|
||||
费毛毛,女,4201858,90.4
|
||||
乐而奚,女,4201819,89.8
|
||||
邹带湛,女,4201829,89.5
|
||||
明曹陶,男,4201800,89.2
|
||||
陶秦秦,男,4201804,88.8
|
||||
金郑郑,男,4201812,88.5
|
||||
彭唐华,男,4201840,88.3
|
||||
禹卫卫,男,4201853,88.2
|
||||
米伏卫,女,4201841,88.0
|
||||
雷成成,女,4201828,87.5
|
||||
明曹曹,男,4201821,86.9
|
||||
邹苏苏,男,4201826,86.6
|
||||
杨卫潘,女,4201855,86.5
|
||||
何韦韦,男,4201825,85.5
|
||||
冯计计,男,4201805,84.5
|
||||
康章朱,女,4201854,82.8
|
||||
梁朱朱,女,4201801,82.0
|
||||
鲍李郎,女,4201814,82.0
|
||||
汤朱故,男,4201839,81.6
|
||||
袁褚褚,男,4201808,81.0
|
||||
卫袁张,女,4201850,80.9
|
||||
雷伏伏,女,4201844,80.8
|
||||
平酆范,男,4201845,80.8
|
||||
平喻华,男,4201833,80.7
|
||||
卜周禹,男,4201824,79.9
|
||||
华吕而,女,4201820,79.5
|
||||
穆蒋蒋,男,4201802,78.2
|
||||
云邹章,女,4201846,78.1
|
||||
罗褚褚,女,4201810,78.0
|
||||
谢奚洪,男,4201803,77.9
|
||||
何地地,女,4201813,77.9
|
||||
卫沈沈,女,4201852,77.8
|
||||
姚分米,男,4201851,77.2
|
||||
陶任任,女,4201827,77.1
|
||||
禹杨鲁,女,4201811,76.2
|
||||
史何飞,男,4201834,76.2
|
||||
臧祝宋,女,4201859,76.0
|
||||
倪卫卫,男,4201832,75.7
|
||||
陶唐尤,女,4201847,75.6
|
||||
韩曹曹,女,4201807,75.5
|
||||
苗蒋范,女,4201818,75.5
|
||||
元彭张,男,4201837,74.8
|
||||
彭三杨,男,4201848,74.8
|
||||
郎三宋,男,4201836,74.3
|
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,Java语言程序设计
|
||||
萧唐唐,男,4201838,94.7
|
||||
禹杨鲁,女,4201811,94.1
|
||||
史何飞,男,4201834,94.1
|
||||
金郑郑,男,4201812,93.9
|
||||
姚分米,男,4201851,93.7
|
||||
汤朱故,男,4201839,93.3
|
||||
彭唐华,男,4201840,92.3
|
||||
葛项项,男,4201830,90.9
|
||||
陶韩韩,男,4201816,90.7
|
||||
严屈尤,女,4201809,90.6
|
||||
平喻华,男,4201833,90.6
|
||||
和苗宋,男,4201857,90.6
|
||||
鲍李郎,女,4201814,90.5
|
||||
纪奚昌,男,4201849,90.3
|
||||
何地地,女,4201813,89.8
|
||||
明曹曹,男,4201821,89.8
|
||||
穆蒋蒋,男,4201802,89.6
|
||||
何韦韦,男,4201825,89.3
|
||||
卫沈沈,女,4201852,89.1
|
||||
倪卫卫,男,4201832,88.8
|
||||
费谢蒋,女,4201823,88.6
|
||||
费襟计,男,4201843,88.5
|
||||
祝魏魏,男,4201806,88.3
|
||||
薛尤尤,女,4201831,88.1
|
||||
彭三杨,男,4201848,88.1
|
||||
梁朱朱,女,4201801,88.0
|
||||
卜周禹,男,4201824,87.4
|
||||
陶任任,女,4201827,87.3
|
||||
汤邹邹,女,4201842,87.1
|
||||
韩曹曹,女,4201807,86.4
|
||||
苗蒋范,女,4201818,86.1
|
||||
臧祝宋,女,4201859,86.1
|
||||
华吕而,女,4201820,85.1
|
||||
邹苏苏,男,4201826,85.1
|
||||
谢昌昌,女,4201822,84.7
|
||||
云邹章,女,4201846,84.6
|
||||
舒米襟,男,4201817,84.3
|
||||
袁褚褚,男,4201808,83.9
|
||||
邹带湛,女,4201829,83.9
|
||||
雷成成,女,4201828,83.8
|
||||
元彭张,男,4201837,82.2
|
||||
冯计计,男,4201805,81.0
|
||||
雷伏伏,女,4201844,80.3
|
||||
平酆范,男,4201845,79.7
|
||||
陶唐尤,女,4201847,79.4
|
||||
费毛毛,女,4201858,79.0
|
||||
谢奚洪,男,4201803,78.6
|
||||
陶秦秦,男,4201804,78.6
|
||||
康章朱,女,4201854,78.6
|
||||
米伏卫,女,4201841,77.0
|
||||
卫袁张,女,4201850,76.9
|
||||
明曹陶,男,4201800,76.8
|
||||
萧韩韩,女,4201815,75.4
|
||||
郎三宋,男,4201836,75.4
|
||||
罗褚褚,女,4201810,75.0
|
||||
杨卫潘,女,4201855,75.0
|
||||
葛喻计,男,4201856,74.4
|
||||
乐而奚,女,4201819,74.2
|
||||
禹卫卫,男,4201853,74.2
|
||||
顾舒舒,女,4201835,74.0
|
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,Python程序设计基础
|
||||
梁朱朱,女,4201801,94.4
|
||||
平酆范,男,4201845,94.2
|
||||
金郑郑,男,4201812,93.9
|
||||
费襟计,男,4201843,93.3
|
||||
乐而奚,女,4201819,92.2
|
||||
彭唐华,男,4201840,91.9
|
||||
何地地,女,4201813,91.8
|
||||
何韦韦,男,4201825,91.3
|
||||
萧唐唐,男,4201838,91.3
|
||||
郎三宋,男,4201836,90.8
|
||||
萧韩韩,女,4201815,90.4
|
||||
彭三杨,男,4201848,90.4
|
||||
卫沈沈,女,4201852,90.0
|
||||
葛喻计,男,4201856,90.0
|
||||
邹带湛,女,4201829,89.3
|
||||
康章朱,女,4201854,89.3
|
||||
谢昌昌,女,4201822,88.7
|
||||
邹苏苏,男,4201826,88.7
|
||||
汤朱故,男,4201839,88.5
|
||||
薛尤尤,女,4201831,87.9
|
||||
舒米襟,男,4201817,87.8
|
||||
平喻华,男,4201833,87.2
|
||||
罗褚褚,女,4201810,86.9
|
||||
明曹曹,男,4201821,86.9
|
||||
鲍李郎,女,4201814,86.7
|
||||
苗蒋范,女,4201818,86.7
|
||||
臧祝宋,女,4201859,86.7
|
||||
倪卫卫,男,4201832,86.2
|
||||
陶任任,女,4201827,85.7
|
||||
卜周禹,男,4201824,84.8
|
||||
杨卫潘,女,4201855,84.7
|
||||
穆蒋蒋,男,4201802,83.0
|
||||
纪奚昌,男,4201849,82.6
|
||||
云邹章,女,4201846,82.5
|
||||
雷成成,女,4201828,82.4
|
||||
卫袁张,女,4201850,82.4
|
||||
袁褚褚,男,4201808,81.5
|
||||
禹杨鲁,女,4201811,80.7
|
||||
费谢蒋,女,4201823,80.7
|
||||
冯计计,男,4201805,80.5
|
||||
费毛毛,女,4201858,80.4
|
||||
和苗宋,男,4201857,79.2
|
||||
禹卫卫,男,4201853,78.8
|
||||
祝魏魏,男,4201806,78.0
|
||||
姚分米,男,4201851,77.1
|
||||
韩曹曹,女,4201807,76.9
|
||||
雷伏伏,女,4201844,76.9
|
||||
陶唐尤,女,4201847,76.8
|
||||
汤邹邹,女,4201842,76.4
|
||||
陶秦秦,男,4201804,76.3
|
||||
严屈尤,女,4201809,76.1
|
||||
史何飞,男,4201834,76.0
|
||||
葛项项,男,4201830,75.8
|
||||
陶韩韩,男,4201816,75.1
|
||||
米伏卫,女,4201841,74.9
|
||||
谢奚洪,男,4201803,74.7
|
||||
元彭张,男,4201837,74.5
|
||||
明曹陶,男,4201800,74.2
|
||||
华吕而,女,4201820,74.2
|
||||
顾舒舒,女,4201835,74.0
|
|
184
期末大作业/作业1-2-4.py
184
期末大作业/作业1-2-4.py
|
@ -1,184 +0,0 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
import random as rd
|
||||
import csv
|
||||
import pandas as pd
|
||||
FirstName = '赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁'
|
||||
LastName = '豫章故郡洪都新府星分翼轸地接衡庐襟三江而带五湖郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜飞李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁'
|
||||
#二维字典定义
|
||||
data_struc = {'structure': {'姓名': '', '性别': '', '学号': '', 'Python程序设计基础': '', '计算机导论': '', '离散数学': '', '数据结构': '', 'C语言程序设计': '', 'Java语言程序设计': '', '算法导论': '', '总分': ''}}
|
||||
#学生总字典定义
|
||||
stuDic = {}
|
||||
stuList=[]
|
||||
stuList = stuDic.values()
|
||||
# 生成学生个人字典
|
||||
def gennerateStu(i, name, sex, number, pythonMark, htmlMark, mathMark, dataMark, cMark, javaMark, methodMark):
|
||||
stuDic[i] = {}
|
||||
stuDic[i]['姓名'] = name
|
||||
stuDic[i]['性别'] = sex
|
||||
stuDic[i]['学号'] = number
|
||||
stuDic[i]['Python程序设计基础'] = pythonMark
|
||||
stuDic[i]['计算机导论'] = htmlMark
|
||||
stuDic[i]['离散数学'] = mathMark
|
||||
stuDic[i]['数据结构'] = dataMark
|
||||
stuDic[i]['C语言程序设计'] = cMark
|
||||
stuDic[i]['Java语言程序设计'] = javaMark
|
||||
stuDic[i]['算法导论'] = methodMark
|
||||
stuDic[i]['总分'] = round(stuDic[i]['Python程序设计基础'] + stuDic[i]['计算机导论'] + stuDic[i]['离散数学'] + stuDic[i]['数据结构'] + stuDic[i]['C语言程序设计'] + stuDic[i]['Java语言程序设计'] + stuDic[i]['算法导论'],1)
|
||||
|
||||
#学生信息设置
|
||||
def gennerator():
|
||||
for i in range(60):
|
||||
xing = rd.choice(FirstName)
|
||||
ming = "".join(rd.choice(LastName) for i in range(2))
|
||||
name = str(rd.choice(xing)) + str("".join(rd.choice(ming) for i in range(2)))
|
||||
sex = rd.choice("男女")
|
||||
number = i + 4201800
|
||||
pythonMark = round(rd.uniform(74, 95), 1)
|
||||
htmlMark = round(rd.uniform(74, 95), 1)
|
||||
mathMark = round(rd.uniform(74, 95), 1)
|
||||
dataMark = round(rd.uniform(74, 95), 1)
|
||||
cMark = round(rd.uniform(74, 95), 1)
|
||||
javaMark = round(rd.uniform(74, 95), 1)
|
||||
methodMark = round(rd.uniform(74, 95), 1)
|
||||
gennerateStu(i, name, sex, number, pythonMark, htmlMark, mathMark, dataMark, cMark, javaMark, methodMark)
|
||||
|
||||
# 写入csv
|
||||
def writeCSV():
|
||||
with open("成绩表.csv", "w") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(stuDic[i])
|
||||
|
||||
def sortPythonMark():
|
||||
python = sorted(stuList, key=lambda i:i['Python程序设计基础'], reverse = True)
|
||||
with open("Python 成绩降序表.csv", "w", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(python[i])
|
||||
data = pd.read_csv("Python 成绩降序表.csv", encoding="utf-8")
|
||||
data1=data.drop(["离散数学"],axis=1)
|
||||
data2=data1.drop(["计算机导论"],axis=1)
|
||||
data3=data2.drop(["数据结构"],axis=1)
|
||||
data4=data3.drop(["C语言程序设计"],axis=1)
|
||||
data5=data4.drop(["Java语言程序设计"],axis=1)
|
||||
data6=data5.drop(["算法导论"],axis=1)
|
||||
data7=data6.drop(["总分"],axis=1)
|
||||
data7.to_csv('Python 成绩降序表.csv', header=data_struc, index=False)
|
||||
|
||||
def sortJavaMark():
|
||||
java = sorted(stuList, key=lambda i:i['Java语言程序设计'], reverse = True)
|
||||
with open("Java 成绩降序表.csv", "w", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(java[i])
|
||||
data = pd.read_csv("Java 成绩降序表.csv", encoding="utf-8")
|
||||
data1=data.drop(["离散数学"],axis=1)
|
||||
data2=data1.drop(["计算机导论"],axis=1)
|
||||
data3=data2.drop(["数据结构"],axis=1)
|
||||
data4=data3.drop(["C语言程序设计"],axis=1)
|
||||
data5=data4.drop(["Python程序设计基础"],axis=1)
|
||||
data6=data5.drop(["算法导论"],axis=1)
|
||||
data7=data6.drop(["总分"],axis=1)
|
||||
data7.to_csv('Java 成绩降序表.csv', header=data_struc, index=False)
|
||||
|
||||
def sortHTMLMark():
|
||||
html = sorted(stuList, key=lambda i:i['计算机导论'], reverse = True)
|
||||
with open("计算机导论成绩降序表.csv", "w", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(html[i])
|
||||
data = pd.read_csv("计算机导论成绩降序表.csv", encoding="utf-8")
|
||||
data1=data.drop(["离散数学"],axis=1)
|
||||
data2=data1.drop(["Python程序设计基础"],axis=1)
|
||||
data3=data2.drop(["数据结构"],axis=1)
|
||||
data4=data3.drop(["C语言程序设计"],axis=1)
|
||||
data5=data4.drop(["Java语言程序设计"],axis=1)
|
||||
data6=data5.drop(["算法导论"],axis=1)
|
||||
data7=data6.drop(["总分"],axis=1)
|
||||
data7.to_csv('计算机导论成绩降序表.csv', header=data_struc, index=False)
|
||||
|
||||
def sortMathMark():
|
||||
Math = sorted(stuList, key=lambda i:i['离散数学'], reverse = True)
|
||||
with open("离散数学成绩降序表.csv", "w", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(Math[i])
|
||||
data = pd.read_csv("离散数学成绩降序表.csv", encoding="utf-8")
|
||||
data1=data.drop(["计算机导论"],axis=1)
|
||||
data2=data1.drop(["Python程序设计基础"],axis=1)
|
||||
data3=data2.drop(["数据结构"],axis=1)
|
||||
data4=data3.drop(["C语言程序设计"],axis=1)
|
||||
data5=data4.drop(["Java语言程序设计"],axis=1)
|
||||
data6=data5.drop(["算法导论"],axis=1)
|
||||
data7=data6.drop(["总分"],axis=1)
|
||||
data7.to_csv('离散数学成绩降序表.csv', header=data_struc, index=False)
|
||||
|
||||
def sortDataMark():
|
||||
Data = sorted(stuList, key=lambda i:i['数据结构'], reverse = True)
|
||||
with open("数据结构成绩降序表.csv", "w", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(Data[i])
|
||||
data = pd.read_csv("数据结构成绩降序表.csv", encoding="utf-8")
|
||||
data1=data.drop(["离散数学"],axis=1)
|
||||
data2=data1.drop(["Java语言程序设计"],axis=1)
|
||||
data3=data2.drop(["计算机导论"],axis=1)
|
||||
data4=data3.drop(["C语言程序设计"],axis=1)
|
||||
data5=data4.drop(["Python程序设计基础"],axis=1)
|
||||
data6=data5.drop(["算法导论"],axis=1)
|
||||
data7=data6.drop(["总分"],axis=1)
|
||||
data7.to_csv('数据结构成绩降序表.csv', header=data_struc, index=False)
|
||||
|
||||
def sortCMark():
|
||||
C = sorted(stuList, key=lambda i:i['C语言程序设计'], reverse = True)
|
||||
with open("C语言成绩降序表.csv", "w", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(C[i])
|
||||
data = pd.read_csv("C语言成绩降序表.csv", encoding="utf-8")
|
||||
data1=data.drop(["离散数学"],axis=1)
|
||||
data2=data1.drop(["Java语言程序设计"],axis=1)
|
||||
data3=data2.drop(["数据结构"],axis=1)
|
||||
data4=data3.drop(["算法导论"],axis=1)
|
||||
data5=data4.drop(["Python程序设计基础"],axis=1)
|
||||
data6=data5.drop(["计算机导论"],axis=1)
|
||||
data7=data6.drop(["总分"],axis=1)
|
||||
data7.to_csv('C语言成绩降序表.csv', header=data_struc, index=False)
|
||||
|
||||
def sortMethMark():
|
||||
Meth = sorted(stuList, key=lambda i:i['算法导论'], reverse = True)
|
||||
with open("算法导论成绩降序表.csv", "w", encoding="utf-8") as file:
|
||||
writer = csv.DictWriter(file, fieldnames=data_struc['structure'].keys())
|
||||
writer.writeheader()
|
||||
for i in range(60):
|
||||
writer.writerow(Meth[i])
|
||||
data = pd.read_csv("算法导论成绩降序表.csv", encoding="utf-8")
|
||||
data1=data.drop(["离散数学"],axis=1)
|
||||
data2=data1.drop(["Python程序设计基础"],axis=1)
|
||||
data3=data2.drop(["数据结构"],axis=1)
|
||||
data4=data3.drop(["C语言程序设计"],axis=1)
|
||||
data5=data4.drop(["Java语言程序设计"],axis=1)
|
||||
data6=data5.drop(["计算机导论"],axis=1)
|
||||
data7=data6.drop(["总分"],axis=1)
|
||||
data7.to_csv('算法导论成绩降序表.csv', header=data_struc, index=False)
|
||||
|
||||
def main():
|
||||
gennerator()
|
||||
writeCSV()
|
||||
sortPythonMark()
|
||||
sortJavaMark()
|
||||
sortHTMLMark()
|
||||
sortMathMark()
|
||||
sortDataMark()
|
||||
sortCMark()
|
||||
sortMethMark()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
232
期末大作业/作业3.py
232
期末大作业/作业3.py
|
@ -1,232 +0,0 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
import csv
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# 设置字体
|
||||
plt.style.use('ggplot')
|
||||
|
||||
def python():
|
||||
interval1 = 0
|
||||
interval2 = 0
|
||||
interval3 = 0
|
||||
with open("Python 成绩降序表.csv", "r", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[3] for row in reader]
|
||||
python = list(column)
|
||||
del python[0]
|
||||
for i in range(len(python)):
|
||||
if 70 < eval(python[i]) <= 80:
|
||||
interval1 += 1
|
||||
if 80 < eval(python[i]) <= 90:
|
||||
interval2 += 1
|
||||
if 90 < eval(python[i]) <= 100:
|
||||
interval3 += 1
|
||||
# 横坐标列表
|
||||
interval = ['70-80', '80-90', '90-100']
|
||||
# 纵坐标列表
|
||||
intervalNum = [interval1, interval2, interval3]
|
||||
|
||||
plt.title('Python') # 表名
|
||||
plt.bar(x=interval, height=intervalNum, color='steelblue', alpha=0.8) # 柱状样式
|
||||
# 合成元组进行输出具体数据(可不要)
|
||||
for x1, yy in zip(interval, intervalNum):
|
||||
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=20, rotation=0)
|
||||
# y轴的区间(传入区间)
|
||||
plt.ylim((0, 40))
|
||||
# 显示图表
|
||||
plt.show()
|
||||
|
||||
|
||||
def html():
|
||||
interval1 = 0
|
||||
interval2 = 0
|
||||
interval3 = 0
|
||||
with open("计算机导论成绩降序表.csv", "r", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[3] for row in reader]
|
||||
html = list(column)
|
||||
del html[0]
|
||||
for i in range(len(html)):
|
||||
if 70 < eval(html[i]) <= 80:
|
||||
interval1 += 1
|
||||
if 80 < eval(html[i]) <= 90:
|
||||
interval2 += 1
|
||||
if 90 < eval(html[i]) <= 100:
|
||||
interval3 += 1
|
||||
interval = ['70-80', '80-90', '90-100']
|
||||
intervalNum = [interval1, interval2, interval3]
|
||||
plt.title('Computer Introduction')
|
||||
plt.bar(x=interval, height=intervalNum, color='steelblue', alpha=0.8)
|
||||
for x1, yy in zip(interval, intervalNum):
|
||||
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=20, rotation=0)
|
||||
plt.ylim((0, 40))
|
||||
plt.show()
|
||||
|
||||
|
||||
def math():
|
||||
interval1 = 0
|
||||
interval2 = 0
|
||||
interval3 = 0
|
||||
with open("离散数学成绩降序表.csv", "r", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[3] for row in reader]
|
||||
math = list(column)
|
||||
del math[0]
|
||||
for i in range(len(math)):
|
||||
if 70 < eval(math[i]) <= 80:
|
||||
interval1 += 1
|
||||
if 80 < eval(math[i]) <= 90:
|
||||
interval2 += 1
|
||||
if 90 < eval(math[i]) <= 100:
|
||||
interval3 += 1
|
||||
interval = ['70-80', '80-90', '90-100']
|
||||
intervalNum = [interval1, interval2, interval3]
|
||||
plt.title('Math')
|
||||
plt.bar(x=interval, height=intervalNum, color='steelblue', alpha=0.8)
|
||||
for x1, yy in zip(interval, intervalNum):
|
||||
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=20, rotation=0)
|
||||
plt.ylim((0, 40))
|
||||
plt.show()
|
||||
|
||||
|
||||
def data():
|
||||
interval1 = 0
|
||||
interval2 = 0
|
||||
interval3 = 0
|
||||
with open("数据结构成绩降序表.csv", "r", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[3] for row in reader]
|
||||
math = list(column)
|
||||
del math[0]
|
||||
for i in range(len(math)):
|
||||
if 70 < eval(math[i]) <= 80:
|
||||
interval1 += 1
|
||||
if 80 < eval(math[i]) <= 90:
|
||||
interval2 += 1
|
||||
if 90 < eval(math[i]) <= 100:
|
||||
interval3 += 1
|
||||
interval = ['70-80', '80-90', '90-100']
|
||||
intervalNum = [interval1, interval2, interval3]
|
||||
plt.title('Data calMethture')
|
||||
plt.bar(x=interval, height=intervalNum, color='steelblue', alpha=0.8)
|
||||
for x1, yy in zip(interval, intervalNum):
|
||||
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=20, rotation=0)
|
||||
plt.ylim((0, 40))
|
||||
plt.show()
|
||||
|
||||
|
||||
def c():
|
||||
interval1 = 0
|
||||
interval2 = 0
|
||||
interval3 = 0
|
||||
with open("C语言成绩降序表.csv", "r", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[3] for row in reader]
|
||||
c = list(column)
|
||||
del c[0]
|
||||
for i in range(len(c)):
|
||||
if 70 < eval(c[i]) <= 80:
|
||||
interval1 += 1
|
||||
if 80 < eval(c[i]) <= 90:
|
||||
interval2 += 1
|
||||
if 90 < eval(c[i]) <= 100:
|
||||
interval3 += 1
|
||||
interval = ['70-80', '80-90', '90-100']
|
||||
intervalNum = [interval1, interval2, interval3]
|
||||
plt.title('C Program')
|
||||
plt.bar(x=interval, height=intervalNum, color='steelblue', alpha=0.8)
|
||||
for x1, yy in zip(interval, intervalNum):
|
||||
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=20, rotation=0)
|
||||
plt.ylim((0, 40))
|
||||
plt.show()
|
||||
|
||||
|
||||
def java():
|
||||
interval1 = 0
|
||||
interval2 = 0
|
||||
interval3 = 0
|
||||
with open("Java 成绩降序表.csv", "r", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[3] for row in reader]
|
||||
java = list(column)
|
||||
del java[0]
|
||||
for i in range(len(java)):
|
||||
if 70 < eval(java[i]) <= 80:
|
||||
interval1 += 1
|
||||
if 80 < eval(java[i]) <= 90:
|
||||
interval2 += 1
|
||||
if 90 < eval(java[i]) <= 100:
|
||||
interval3 += 1
|
||||
interval = ['70-80', '80-90', '90-100']
|
||||
intervalNum = [interval1, interval2, interval3]
|
||||
plt.title('Java Programming')
|
||||
plt.bar(x=interval, height=intervalNum, color='steelblue', alpha=0.8)
|
||||
for x1, yy in zip(interval, intervalNum):
|
||||
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=20, rotation=0)
|
||||
plt.ylim((0, 40))
|
||||
plt.show()
|
||||
|
||||
|
||||
def calMeth():
|
||||
interval1 = 0
|
||||
interval2 = 0
|
||||
interval3 = 0
|
||||
with open("算法导论成绩降序表.csv", "r", encoding="utf-8") as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[3] for row in reader]
|
||||
calMeth = list(column)
|
||||
del calMeth[0]
|
||||
for i in range(len(calMeth)):
|
||||
if 70 < eval(calMeth[i]) <= 80:
|
||||
interval1 += 1
|
||||
if 80 < eval(calMeth[i]) <= 90:
|
||||
interval2 += 1
|
||||
if 90 < eval(calMeth[i]) <= 100:
|
||||
interval3 += 1
|
||||
interval = ['70-80', '80-90', '90-100']
|
||||
intervalNum = [interval1, interval2, interval3]
|
||||
plt.title('Calculating Methods')
|
||||
plt.bar(x=interval, height=intervalNum, color='steelblue', alpha=0.8)
|
||||
for x1, yy in zip(interval, intervalNum):
|
||||
plt.text(x1, yy + 1, str(yy), ha='center', va='bottom', fontsize=20, rotation=0)
|
||||
plt.ylim((0, 40))
|
||||
plt.show()
|
||||
|
||||
def main():
|
||||
print('本程序可查看各课程成绩中各区间的人数分布。')
|
||||
print('请输入要查看的课程:')
|
||||
print('1.Python 程序设计基础')
|
||||
print('2.计算机导论')
|
||||
print('3.离散数学')
|
||||
print('4.数据结构')
|
||||
print('5.C语言程序设计')
|
||||
print('5.Java语言程序设计')
|
||||
print('7.算法导论')
|
||||
while (1):
|
||||
num = eval(input("请输入要查看的课程编号,输入0则退出:"))
|
||||
if num == 1:
|
||||
python()
|
||||
if num == 2:
|
||||
html()
|
||||
if num == 3:
|
||||
math()
|
||||
if num == 4:
|
||||
data()
|
||||
if num == 5:
|
||||
c()
|
||||
if num == 6:
|
||||
java()
|
||||
if num == 7:
|
||||
calMeth()
|
||||
if num == 0:
|
||||
break
|
||||
|
||||
if __name__ == '__main__':
|
||||
'''python()
|
||||
html()
|
||||
math()
|
||||
data()
|
||||
c()
|
||||
java()
|
||||
calMeth()'''
|
||||
main()
|
|
@ -1,92 +0,0 @@
|
|||
# -*- coding:utf-8 -*-
|
||||
import csv
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
|
||||
stu = []
|
||||
StuListFinal = []
|
||||
|
||||
with open("成绩表.csv", "r", encoding='utf-8') as file:
|
||||
reader = csv.reader(file)
|
||||
column = [row[-1] for row in reader]
|
||||
score = list(column)
|
||||
del score[0]
|
||||
|
||||
def display(lb):
|
||||
print('总分分别为')
|
||||
for i in range(0, len(lb), 5):
|
||||
yield lb[i:i + 5]
|
||||
|
||||
def cal():
|
||||
print(*display(score), sep="\n")
|
||||
print("\n数据计算:")
|
||||
total, fangcha, avr = 0, 0, 0
|
||||
|
||||
# 平均分
|
||||
for i in range(0, len(score)):
|
||||
total += eval(score[i])
|
||||
avr = total / 60
|
||||
for i in range(0, len(score)):
|
||||
fangcha += ((eval(score[i]) - avr) ** 2)
|
||||
|
||||
print("所有学生最高分为{2:.2f},最低分为{3:.2f},平均分为{0:.2f},方差为{1:.2f}".format(avr, fangcha / 60, float(max(score)), float(min(score))))
|
||||
|
||||
#work6-7
|
||||
def readcsv():
|
||||
f = '成绩表.csv'
|
||||
s = pd.read_csv(f, usecols=[3, 4, 5, 6, 7, 8, 9])
|
||||
return np.array(s)
|
||||
|
||||
def sorta(cv):
|
||||
return cv[-1]
|
||||
|
||||
StuListFinal = readcsv()
|
||||
|
||||
def scoresAbsolute(s, stu1):
|
||||
TEStu = []
|
||||
for stu2 in range(len(StuListFinal)):
|
||||
if stu2 != stu1:
|
||||
num = []
|
||||
absSum = 0
|
||||
num.append(stu2)
|
||||
for i in range(len(s[stu1])):
|
||||
absSum += abs(s[stu1][i] - s[stu2][i])
|
||||
num.append(absSum)
|
||||
TEStu.append(num)
|
||||
TEStu = sorted(TEStu, key=sorta)
|
||||
AbSumLs = []
|
||||
sum = 0
|
||||
AbSumLs.append(stu1)
|
||||
|
||||
for i in range(9):
|
||||
sum += TEStu[i][-1]
|
||||
AbSumLs.append(TEStu[i][0])
|
||||
AbSumLs.append(sum)
|
||||
stu.append(AbSumLs)
|
||||
|
||||
def DrawSD(listtotal):
|
||||
plt.style.use('ggplot')
|
||||
x = ['Python', 'Computer', 'Math', 'Data', 'C', 'Java', 'CalMethod']
|
||||
for i in range(10):
|
||||
y = StuListFinal[listtotal[i]]
|
||||
print(StuListFinal[listtotal])
|
||||
plt.scatter(x, y)
|
||||
plt.show()
|
||||
|
||||
def work7():
|
||||
Final = []
|
||||
|
||||
for i in range(len(StuListFinal)):
|
||||
scoresAbsolute(StuListFinal, i)
|
||||
SortedStuList = sorted(stu, key=sorta)
|
||||
for j in range(10):
|
||||
Final.append(SortedStuList[0][j])
|
||||
DrawSD(Final)
|
||||
|
||||
def main():
|
||||
work7()
|
||||
cal()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,Python程序设计基础,计算机导论,离散数学,数据结构,C语言程序设计,Java语言程序设计,算法导论,总分
|
||||
明曹陶,男,4201800,74.2,87.8,83.2,83.2,89.2,76.8,93.3,587.7
|
||||
梁朱朱,女,4201801,94.4,93.8,79.7,93.5,82.0,88.0,94.1,625.5
|
||||
穆蒋蒋,男,4201802,83.0,90.3,84.3,92.6,78.2,89.6,82.9,600.9
|
||||
谢奚洪,男,4201803,74.7,76.0,94.6,93.6,77.9,78.6,79.0,574.4
|
||||
陶秦秦,男,4201804,76.3,79.4,80.3,82.7,88.8,78.6,80.1,566.2
|
||||
冯计计,男,4201805,80.5,84.4,94.0,84.7,84.5,81.0,85.4,594.5
|
||||
祝魏魏,男,4201806,78.0,79.6,90.3,88.7,94.4,88.3,89.5,608.8
|
||||
韩曹曹,女,4201807,76.9,94.9,89.6,85.9,75.5,86.4,80.8,590.0
|
||||
袁褚褚,男,4201808,81.5,77.5,90.2,76.2,81.0,83.9,76.1,566.4
|
||||
严屈尤,女,4201809,76.1,80.4,81.3,90.4,93.8,90.6,83.5,596.1
|
||||
罗褚褚,女,4201810,86.9,88.4,82.9,76.5,78.0,75.0,92.2,579.9
|
||||
禹杨鲁,女,4201811,80.7,83.9,92.1,75.5,76.2,94.1,87.3,589.8
|
||||
金郑郑,男,4201812,93.9,76.9,82.7,90.8,88.5,93.9,82.6,609.3
|
||||
何地地,女,4201813,91.8,90.8,95.0,80.3,77.9,89.8,83.4,609.0
|
||||
鲍李郎,女,4201814,86.7,94.6,89.5,87.5,82.0,90.5,90.6,621.4
|
||||
萧韩韩,女,4201815,90.4,93.8,79.2,86.0,94.4,75.4,87.5,606.7
|
||||
陶韩韩,男,4201816,75.1,92.4,90.3,88.1,90.8,90.7,93.6,621.0
|
||||
舒米襟,男,4201817,87.8,92.1,78.8,87.5,90.7,84.3,84.7,605.9
|
||||
苗蒋范,女,4201818,86.7,74.3,92.3,93.5,75.5,86.1,74.3,582.7
|
||||
乐而奚,女,4201819,92.2,88.9,78.3,94.6,89.8,74.2,74.5,592.5
|
||||
华吕而,女,4201820,74.2,77.3,86.4,88.5,79.5,85.1,82.5,573.5
|
||||
明曹曹,男,4201821,86.9,79.2,87.6,79.0,86.9,89.8,78.5,587.9
|
||||
谢昌昌,女,4201822,88.7,74.5,80.8,76.8,92.9,84.7,77.5,575.9
|
||||
费谢蒋,女,4201823,80.7,87.0,84.7,87.3,94.4,88.6,90.8,613.5
|
||||
卜周禹,男,4201824,84.8,87.8,86.3,90.8,79.9,87.4,91.6,608.6
|
||||
何韦韦,男,4201825,91.3,87.0,74.9,76.3,85.5,89.3,87.0,591.3
|
||||
邹苏苏,男,4201826,88.7,77.7,78.2,77.9,86.6,85.1,92.6,586.8
|
||||
陶任任,女,4201827,85.7,81.8,84.1,94.3,77.1,87.3,79.3,589.6
|
||||
雷成成,女,4201828,82.4,92.7,78.6,80.4,87.5,83.8,87.8,593.2
|
||||
邹带湛,女,4201829,89.3,87.8,85.4,78.6,89.5,83.9,92.2,606.7
|
||||
葛项项,男,4201830,75.8,81.5,74.9,82.8,90.6,90.9,93.8,590.3
|
||||
薛尤尤,女,4201831,87.9,84.6,86.1,91.8,94.4,88.1,81.3,614.2
|
||||
倪卫卫,男,4201832,86.2,83.5,93.4,92.9,75.7,88.8,91.5,612.0
|
||||
平喻华,男,4201833,87.2,82.8,82.7,78.2,80.7,90.6,87.8,590.0
|
||||
史何飞,男,4201834,76.0,91.9,82.5,83.4,76.2,94.1,83.1,587.2
|
||||
顾舒舒,女,4201835,74.0,75.9,77.1,79.1,92.8,74.0,88.2,561.1
|
||||
郎三宋,男,4201836,90.8,93.7,85.2,86.8,74.3,75.4,94.7,600.9
|
||||
元彭张,男,4201837,74.5,88.9,86.6,80.3,74.8,82.2,78.7,566.0
|
||||
萧唐唐,男,4201838,91.3,74.0,90.7,94.0,90.5,94.7,94.0,629.2
|
||||
汤朱故,男,4201839,88.5,83.9,93.1,92.9,81.6,93.3,94.2,627.5
|
||||
彭唐华,男,4201840,91.9,78.0,89.4,92.6,88.3,92.3,87.5,620.0
|
||||
米伏卫,女,4201841,74.9,87.6,88.1,83.8,88.0,77.0,89.4,588.8
|
||||
汤邹邹,女,4201842,76.4,89.7,90.1,79.8,91.5,87.1,86.0,600.6
|
||||
费襟计,男,4201843,93.3,79.8,91.7,82.7,93.3,88.5,80.3,609.6
|
||||
雷伏伏,女,4201844,76.9,91.5,83.6,75.5,80.8,80.3,82.4,571.0
|
||||
平酆范,男,4201845,94.2,77.3,78.6,89.9,80.8,79.7,77.1,577.6
|
||||
云邹章,女,4201846,82.5,76.0,91.2,91.4,78.1,84.6,84.6,588.4
|
||||
陶唐尤,女,4201847,76.8,83.0,75.1,77.8,75.6,79.4,89.4,557.1
|
||||
彭三杨,男,4201848,90.4,76.5,94.1,90.4,74.8,88.1,75.1,589.4
|
||||
纪奚昌,男,4201849,82.6,84.7,79.5,78.6,90.5,90.3,84.7,590.9
|
||||
卫袁张,女,4201850,82.4,94.0,75.7,84.2,80.9,76.9,80.5,574.6
|
||||
姚分米,男,4201851,77.1,79.8,81.8,78.5,77.2,93.7,81.8,569.9
|
||||
卫沈沈,女,4201852,90.0,89.7,90.8,83.7,77.8,89.1,85.1,606.2
|
||||
禹卫卫,男,4201853,78.8,76.5,85.6,85.8,88.2,74.2,80.3,569.4
|
||||
康章朱,女,4201854,89.3,91.6,85.1,79.5,82.8,78.6,85.3,592.2
|
||||
杨卫潘,女,4201855,84.7,74.7,77.0,83.8,86.5,75.0,87.1,568.8
|
||||
葛喻计,男,4201856,90.0,92.1,77.3,86.6,93.6,74.4,79.7,593.7
|
||||
和苗宋,男,4201857,79.2,87.4,90.5,92.2,92.1,90.6,82.5,614.5
|
||||
费毛毛,女,4201858,80.4,93.9,87.6,91.5,90.4,79.0,93.3,616.1
|
||||
臧祝宋,女,4201859,86.7,86.6,77.7,91.2,76.0,86.1,87.2,591.5
|
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,数据结构
|
||||
乐而奚,女,4201819,94.6
|
||||
陶任任,女,4201827,94.3
|
||||
萧唐唐,男,4201838,94.0
|
||||
谢奚洪,男,4201803,93.6
|
||||
梁朱朱,女,4201801,93.5
|
||||
苗蒋范,女,4201818,93.5
|
||||
倪卫卫,男,4201832,92.9
|
||||
汤朱故,男,4201839,92.9
|
||||
穆蒋蒋,男,4201802,92.6
|
||||
彭唐华,男,4201840,92.6
|
||||
和苗宋,男,4201857,92.2
|
||||
薛尤尤,女,4201831,91.8
|
||||
费毛毛,女,4201858,91.5
|
||||
云邹章,女,4201846,91.4
|
||||
臧祝宋,女,4201859,91.2
|
||||
金郑郑,男,4201812,90.8
|
||||
卜周禹,男,4201824,90.8
|
||||
严屈尤,女,4201809,90.4
|
||||
彭三杨,男,4201848,90.4
|
||||
平酆范,男,4201845,89.9
|
||||
祝魏魏,男,4201806,88.7
|
||||
华吕而,女,4201820,88.5
|
||||
陶韩韩,男,4201816,88.1
|
||||
鲍李郎,女,4201814,87.5
|
||||
舒米襟,男,4201817,87.5
|
||||
费谢蒋,女,4201823,87.3
|
||||
郎三宋,男,4201836,86.8
|
||||
葛喻计,男,4201856,86.6
|
||||
萧韩韩,女,4201815,86.0
|
||||
韩曹曹,女,4201807,85.9
|
||||
禹卫卫,男,4201853,85.8
|
||||
冯计计,男,4201805,84.7
|
||||
卫袁张,女,4201850,84.2
|
||||
米伏卫,女,4201841,83.8
|
||||
杨卫潘,女,4201855,83.8
|
||||
卫沈沈,女,4201852,83.7
|
||||
史何飞,男,4201834,83.4
|
||||
明曹陶,男,4201800,83.2
|
||||
葛项项,男,4201830,82.8
|
||||
陶秦秦,男,4201804,82.7
|
||||
费襟计,男,4201843,82.7
|
||||
雷成成,女,4201828,80.4
|
||||
何地地,女,4201813,80.3
|
||||
元彭张,男,4201837,80.3
|
||||
汤邹邹,女,4201842,79.8
|
||||
康章朱,女,4201854,79.5
|
||||
顾舒舒,女,4201835,79.1
|
||||
明曹曹,男,4201821,79.0
|
||||
邹带湛,女,4201829,78.6
|
||||
纪奚昌,男,4201849,78.6
|
||||
姚分米,男,4201851,78.5
|
||||
平喻华,男,4201833,78.2
|
||||
邹苏苏,男,4201826,77.9
|
||||
陶唐尤,女,4201847,77.8
|
||||
谢昌昌,女,4201822,76.8
|
||||
罗褚褚,女,4201810,76.5
|
||||
何韦韦,男,4201825,76.3
|
||||
袁褚褚,男,4201808,76.2
|
||||
禹杨鲁,女,4201811,75.5
|
||||
雷伏伏,女,4201844,75.5
|
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,离散数学
|
||||
何地地,女,4201813,95.0
|
||||
谢奚洪,男,4201803,94.6
|
||||
彭三杨,男,4201848,94.1
|
||||
冯计计,男,4201805,94.0
|
||||
倪卫卫,男,4201832,93.4
|
||||
汤朱故,男,4201839,93.1
|
||||
苗蒋范,女,4201818,92.3
|
||||
禹杨鲁,女,4201811,92.1
|
||||
费襟计,男,4201843,91.7
|
||||
云邹章,女,4201846,91.2
|
||||
卫沈沈,女,4201852,90.8
|
||||
萧唐唐,男,4201838,90.7
|
||||
和苗宋,男,4201857,90.5
|
||||
祝魏魏,男,4201806,90.3
|
||||
陶韩韩,男,4201816,90.3
|
||||
袁褚褚,男,4201808,90.2
|
||||
汤邹邹,女,4201842,90.1
|
||||
韩曹曹,女,4201807,89.6
|
||||
鲍李郎,女,4201814,89.5
|
||||
彭唐华,男,4201840,89.4
|
||||
米伏卫,女,4201841,88.1
|
||||
明曹曹,男,4201821,87.6
|
||||
费毛毛,女,4201858,87.6
|
||||
元彭张,男,4201837,86.6
|
||||
华吕而,女,4201820,86.4
|
||||
卜周禹,男,4201824,86.3
|
||||
薛尤尤,女,4201831,86.1
|
||||
禹卫卫,男,4201853,85.6
|
||||
邹带湛,女,4201829,85.4
|
||||
郎三宋,男,4201836,85.2
|
||||
康章朱,女,4201854,85.1
|
||||
费谢蒋,女,4201823,84.7
|
||||
穆蒋蒋,男,4201802,84.3
|
||||
陶任任,女,4201827,84.1
|
||||
雷伏伏,女,4201844,83.6
|
||||
明曹陶,男,4201800,83.2
|
||||
罗褚褚,女,4201810,82.9
|
||||
金郑郑,男,4201812,82.7
|
||||
平喻华,男,4201833,82.7
|
||||
史何飞,男,4201834,82.5
|
||||
姚分米,男,4201851,81.8
|
||||
严屈尤,女,4201809,81.3
|
||||
谢昌昌,女,4201822,80.8
|
||||
陶秦秦,男,4201804,80.3
|
||||
梁朱朱,女,4201801,79.7
|
||||
纪奚昌,男,4201849,79.5
|
||||
萧韩韩,女,4201815,79.2
|
||||
舒米襟,男,4201817,78.8
|
||||
雷成成,女,4201828,78.6
|
||||
平酆范,男,4201845,78.6
|
||||
乐而奚,女,4201819,78.3
|
||||
邹苏苏,男,4201826,78.2
|
||||
臧祝宋,女,4201859,77.7
|
||||
葛喻计,男,4201856,77.3
|
||||
顾舒舒,女,4201835,77.1
|
||||
杨卫潘,女,4201855,77.0
|
||||
卫袁张,女,4201850,75.7
|
||||
陶唐尤,女,4201847,75.1
|
||||
何韦韦,男,4201825,74.9
|
||||
葛项项,男,4201830,74.9
|
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,算法导论
|
||||
郎三宋,男,4201836,94.7
|
||||
汤朱故,男,4201839,94.2
|
||||
梁朱朱,女,4201801,94.1
|
||||
萧唐唐,男,4201838,94.0
|
||||
葛项项,男,4201830,93.8
|
||||
陶韩韩,男,4201816,93.6
|
||||
明曹陶,男,4201800,93.3
|
||||
费毛毛,女,4201858,93.3
|
||||
邹苏苏,男,4201826,92.6
|
||||
罗褚褚,女,4201810,92.2
|
||||
邹带湛,女,4201829,92.2
|
||||
卜周禹,男,4201824,91.6
|
||||
倪卫卫,男,4201832,91.5
|
||||
费谢蒋,女,4201823,90.8
|
||||
鲍李郎,女,4201814,90.6
|
||||
祝魏魏,男,4201806,89.5
|
||||
米伏卫,女,4201841,89.4
|
||||
陶唐尤,女,4201847,89.4
|
||||
顾舒舒,女,4201835,88.2
|
||||
雷成成,女,4201828,87.8
|
||||
平喻华,男,4201833,87.8
|
||||
萧韩韩,女,4201815,87.5
|
||||
彭唐华,男,4201840,87.5
|
||||
禹杨鲁,女,4201811,87.3
|
||||
臧祝宋,女,4201859,87.2
|
||||
杨卫潘,女,4201855,87.1
|
||||
何韦韦,男,4201825,87.0
|
||||
汤邹邹,女,4201842,86.0
|
||||
冯计计,男,4201805,85.4
|
||||
康章朱,女,4201854,85.3
|
||||
卫沈沈,女,4201852,85.1
|
||||
舒米襟,男,4201817,84.7
|
||||
纪奚昌,男,4201849,84.7
|
||||
云邹章,女,4201846,84.6
|
||||
严屈尤,女,4201809,83.5
|
||||
何地地,女,4201813,83.4
|
||||
史何飞,男,4201834,83.1
|
||||
穆蒋蒋,男,4201802,82.9
|
||||
金郑郑,男,4201812,82.6
|
||||
华吕而,女,4201820,82.5
|
||||
和苗宋,男,4201857,82.5
|
||||
雷伏伏,女,4201844,82.4
|
||||
姚分米,男,4201851,81.8
|
||||
薛尤尤,女,4201831,81.3
|
||||
韩曹曹,女,4201807,80.8
|
||||
卫袁张,女,4201850,80.5
|
||||
费襟计,男,4201843,80.3
|
||||
禹卫卫,男,4201853,80.3
|
||||
陶秦秦,男,4201804,80.1
|
||||
葛喻计,男,4201856,79.7
|
||||
陶任任,女,4201827,79.3
|
||||
谢奚洪,男,4201803,79.0
|
||||
元彭张,男,4201837,78.7
|
||||
明曹曹,男,4201821,78.5
|
||||
谢昌昌,女,4201822,77.5
|
||||
平酆范,男,4201845,77.1
|
||||
袁褚褚,男,4201808,76.1
|
||||
彭三杨,男,4201848,75.1
|
||||
乐而奚,女,4201819,74.5
|
||||
苗蒋范,女,4201818,74.3
|
|
|
@ -1,61 +0,0 @@
|
|||
姓名,性别,学号,计算机导论
|
||||
韩曹曹,女,4201807,94.9
|
||||
鲍李郎,女,4201814,94.6
|
||||
卫袁张,女,4201850,94.0
|
||||
费毛毛,女,4201858,93.9
|
||||
梁朱朱,女,4201801,93.8
|
||||
萧韩韩,女,4201815,93.8
|
||||
郎三宋,男,4201836,93.7
|
||||
雷成成,女,4201828,92.7
|
||||
陶韩韩,男,4201816,92.4
|
||||
舒米襟,男,4201817,92.1
|
||||
葛喻计,男,4201856,92.1
|
||||
史何飞,男,4201834,91.9
|
||||
康章朱,女,4201854,91.6
|
||||
雷伏伏,女,4201844,91.5
|
||||
何地地,女,4201813,90.8
|
||||
穆蒋蒋,男,4201802,90.3
|
||||
汤邹邹,女,4201842,89.7
|
||||
卫沈沈,女,4201852,89.7
|
||||
乐而奚,女,4201819,88.9
|
||||
元彭张,男,4201837,88.9
|
||||
罗褚褚,女,4201810,88.4
|
||||
明曹陶,男,4201800,87.8
|
||||
卜周禹,男,4201824,87.8
|
||||
邹带湛,女,4201829,87.8
|
||||
米伏卫,女,4201841,87.6
|
||||
和苗宋,男,4201857,87.4
|
||||
费谢蒋,女,4201823,87.0
|
||||
何韦韦,男,4201825,87.0
|
||||
臧祝宋,女,4201859,86.6
|
||||
纪奚昌,男,4201849,84.7
|
||||
薛尤尤,女,4201831,84.6
|
||||
冯计计,男,4201805,84.4
|
||||
禹杨鲁,女,4201811,83.9
|
||||
汤朱故,男,4201839,83.9
|
||||
倪卫卫,男,4201832,83.5
|
||||
陶唐尤,女,4201847,83.0
|
||||
平喻华,男,4201833,82.8
|
||||
陶任任,女,4201827,81.8
|
||||
葛项项,男,4201830,81.5
|
||||
严屈尤,女,4201809,80.4
|
||||
费襟计,男,4201843,79.8
|
||||
姚分米,男,4201851,79.8
|
||||
祝魏魏,男,4201806,79.6
|
||||
陶秦秦,男,4201804,79.4
|
||||
明曹曹,男,4201821,79.2
|
||||
彭唐华,男,4201840,78.0
|
||||
邹苏苏,男,4201826,77.7
|
||||
袁褚褚,男,4201808,77.5
|
||||
华吕而,女,4201820,77.3
|
||||
平酆范,男,4201845,77.3
|
||||
金郑郑,男,4201812,76.9
|
||||
彭三杨,男,4201848,76.5
|
||||
禹卫卫,男,4201853,76.5
|
||||
谢奚洪,男,4201803,76.0
|
||||
云邹章,女,4201846,76.0
|
||||
顾舒舒,女,4201835,75.9
|
||||
杨卫潘,女,4201855,74.7
|
||||
谢昌昌,女,4201822,74.5
|
||||
苗蒋范,女,4201818,74.3
|
||||
萧唐唐,男,4201838,74.0
|
|
Binary file not shown.
Before Width: | Height: | Size: 152 KiB |
22
飞书集成/上传图片.py
22
飞书集成/上传图片.py
|
@ -1,22 +0,0 @@
|
|||
import requests
|
||||
from requests_toolbelt import MultipartEncoder
|
||||
|
||||
|
||||
# 输入pip install requests_toolbelt 安装依赖库
|
||||
|
||||
def uploadImage():
|
||||
url = "https://open.feishu.cn/open-apis/im/v1/images"
|
||||
form = {'image_type': 'message',
|
||||
'image': (open('birthday.jpeg', 'rb'))} # 需要替换具体的path
|
||||
multi_form = MultipartEncoder(form)
|
||||
headers = {
|
||||
'Authorization': 't-g10439k6JFMJ7BNY2OHNRCNOLF4X2KMIY6LCJDQ7', ## 获取tenant_access_token, 需要替换为实际的token
|
||||
}
|
||||
headers['Content-Type'] = multi_form.content_type
|
||||
response = requests.request("POST", url, headers=headers, data=multi_form)
|
||||
print(response.headers['X-Tt-Logid']) # for debug or oncall
|
||||
print(response.content) # Print Response
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
uploadImage()
|
Loading…
Reference in New Issue