Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm Trying to convert my guessing game scoreboard from CSV to Xlsx but I'm having trouble figuring out the coding for it, does anyone have any idea how to right out the code? I've tried looking up guides and info but I haven't figured anything out through resources so I figured I would try to ask some people instead.

This is the code for my game:

from random import randint       

MIN_GUESS=1                       
MAX_GUESS=100
FILENAME="Scoreboard.csv"
GREETING='''
* Welcome to our guessing game *  '''                     
FAREWELL='''*Thank you for playing our guessing game *
'''
import csv
import os


def playNewGame(gameList):
    name=input("Please enter your name: ")    
    numberToGuess=randint(MIN_GUESS,MAX_GUESS)    
    count=0
    while True:
        guess = int(input("Please make a guess: "))
        count+=1
        if guess > numberToGuess:
            print("Try a smaller number.")
        elif guess < numberToGuess:
            print("Try a larger number")
        else:
            print(f"You guessed the number in {count} tries.")
            break                           
    gameList.append([name,count,' '])
    return gameList

def evaluateBestScore(gameList): 
    minCount=10
    
    for game in gameList:   
        if int(game[1]) < minCount:        
           minCount=int(game[1])        
    for game in gameList:
        if int(game[1])==minCount:
            game[2] = "Best Score" 
        else:
            game[2] = ''
    return gameList


def askToPlayAgain():
    playAgain=input("Do you wish to play again?(Y/N)")
    if playAgain.upper() == 'Y':
        return True
    else:
        return False
    
def showScores(gameList):
    for game in gameList:
        print(game)

def main():         
   
    print(GREETING)
    keepPlaying=True
    gameList=[]
    while keepPlaying:
        gameList=playNewGame(gameList)
        keepPlaying=askToPlayAgain()
    gameList=evaluateBestScore(gameList)
    showScores(gameList)
    csvfile=open("Scoreboard.csv", "w", newline='')
    writer=csv.writer(csvfile,delimiter='',lineterminator="

")
    for listitem in gameList:
        writer.writerow(listitem)
    csvfile.close()
        
    print(FAREWELL)
    
    
main()
question from:https://stackoverflow.com/questions/65623020/convert-csv-to-xlsx-using-openpyxl

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
330 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...