Use the most efficient and simple logic to achieve the same effect from a beginner's…
- User
Use the most efficient and simple logic to achieve the same effect from a beginner's perspective, and don't change my content.:import random import time
greetings = [ "歡迎來到打字遊戲!希望您能在這裏玩得開心!", "嗨!準備好挑戰您的打字速度極限了嗎?", "哈囉!讓我看看您的打字技術有沒有進步!", "我發現您現在天賦越來越優秀了!" ]
grade_description = { 'S': "完美無瑕!", 'A': "非常出色!", 'B': "不錯!", 'C': "有進步!", 'D': "需要操練!", 'F': "再接再厲!" }
difficulty_levels = { 1: "簡單難度", 2: "中等難度", 3: "困難難度", 4: "地獄難度" }
difficulty_texts = { 1: (["Switch", "Router", "Firewall", "Protocol", "Phishing", "Internet", "Authentication", "Encryption", "Virus", "Software", "Hardware"], 1.5), 2: (["Local Area Network", "Wide Area Network", "Operating System", "Central Processing Unit", "Graphics Processing Unit", "Random Access Memory", "Solid State Drive", "Hard Disk Drive", "Database Management System", "Integrated Development Environment"], 5), 3: (["Pneumonoultramicroscopicsilicovolcanoconiosis", "Hippopotomonstrosesquippedaliophobia", "Supercalifragilisticexpialidocious", "Pseudopseudohypoparathyroidism", "Floccinaucinihilipilification", "Antidisestablishmentarianism"], 10), 4: (["Uh, summa-lumma, dooma-lumma, you assumin'. I'm a human What I gotta do to get it through to you I'm superhuman?", "Innovative and I'm made of rubber so that anything you say is ricochetin' off of me, and it'll glue to you and", "I'm devastating, more than ever demonstrating How to give an audience a feeling like it's levitating", "Never fading, and I know the haters are forever waiting For the day that they can say I fell off, they'll be celebrating", "'Cause I know the way to get 'em motivated I make elevating music, you make elevator music", "Oh, he's too mainstream Well, that's what they do when they get jealous, they confuse it It's not hip-hop, it's pop", "cause I found a hella way to fuse it With rock, shock rap with Doc Throw on 'Lose Yourself' and make'em lose it"], 30) }
def welcome(): username = input("請輸入您的用戶名稱:") print(f"{username},{random.choice(greetings)}") return username
def grade(accuracy, time_taken, difficulty_level): base_score = accuracy * ((difficulty_level)*10/ (time_taken)) # 使时间对得分影响减少,并且更平滑 difficulty_multiplier = 1 + (difficulty_level - 1) * 0.2 # 根据难度增加得分系数 score = base_score * difficulty_multiplier score = max(0, min(score, 100)) if score >= 95: grade = 'S' elif score >= 85: grade = 'A' elif score >= 75: grade = 'B' elif score >= 65: grade = 'C' elif score >= 55: grade = 'D' else: grade = 'F'
codereturn grade, grade_description[grade], scoredef accuracy(user_input, correct_text): """計算準確率""" user_words = user_input.split() correct_words = correct_text.split() correct_count = 0 for i in range(len(user_words)): if user_words[i] == correct_words[i]: correct_count += 1 return (correct_count / len(correct_words)) * 100
def check_text(user_input, correct_text): """檢查文本""" user_words = user_input.split() correct_words = correct_text.split() result = "" for i in range(len(user_words)): if user_words[i] == correct_words[i]: result += user_words[i] + " " else: result += f"{user_words[i]} ({correct_words[i]}) " return result.strip()
Assistant