Thread: Python Program

Results 1 to 4 of 4
  1. #1 Python Program 
    Registered Member
    Join Date
    Mar 2016
    Posts
    94
    Thanks given
    2
    Thanks received
    4
    Rep Power
    11
    I have a Python program task to do.

    Display the date when program is ran (done)
    First to import names from a .csv file (done)
    Calculate random numbers between 0 and 10, 5 numbers (done)
    For each person add the total of these scores up (incomplete)
    Remove the max number for each person (incomplete)
    Remove the minimum number for each person (incomplete)
    Add up the remaining 3 numbers and output who has the highest score (incomplete)

    Code:
    import csv
    import datetime
    import random
    
    def getdata(name,country):
        with open("data.csv") as f:
            reader = csv.reader(f)
            for row in reader:
               name.append(row[0]) 
                country.append(row[1])
                
    def getDate():
        #works out current date
        current_date = datetime.date.today()
        
        return current_date
    
    def randomScore():
        #returns 5 numbers between 1 and 10
        for i in range(5):
            yield random.randint(0, 10)
    
           
        
        
      
    def welcome(name,country,current_date,scores):
        date = "{:%d, %B %Y}".format(current_date)
        print("      Welcome ",date,"")
        print("      List of the names and scores below!\n")
        for index in range(len(diver_name)):
            print(name[index], "-", country[index])
            for scores in randomScore():
                print("Score  %i" %(scores))
                
    
    def main():
        name = []
        country = []
        scores = []
        getdata(name,country)
        date = getDate()
        welcome(name,country,date,scores) 
    if __name__ == "__main__":
        main()
    Basically I'm unsure how to add up say first 5 scores and then from 5-10 or whatever, there is 5 names I need 5 total scores for.
    Reply With Quote  
     

  2. #2  
    Server Developer
    Argyros's Avatar
    Join Date
    Apr 2011
    Posts
    498
    Thanks given
    25
    Thanks received
    31
    Rep Power
    23
    Do you need 5 random numbers for each person or just 5 random numbers, 1 random number per name?
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Mar 2016
    Posts
    94
    Thanks given
    2
    Thanks received
    4
    Rep Power
    11
    Quote Originally Posted by Argyros View Post
    Do you need 5 random numbers for each person or just 5 random numbers, 1 random number per name?
    Needs to be 5 each person, 5 people so 25 random numbers in total although thinking ahead, I'm expected to use the findMaxiumum function and take the highest away from each member, then use the findMinimum and take the smallest number and add the remaining 3 to find who has the highest score. It's a lot of BS but yeah.
    Reply With Quote  
     

  4. #4 Potential solutions 
    Registered Member
    Join Date
    Dec 2016
    Posts
    21
    Thanks given
    1
    Thanks received
    2
    Rep Power
    11
    To display total score for each diver define two variables

    One list and one integer number

    all_scores is a list and keeps track on what the diver has scored overall.
    total_score is just an integer of the total score, Total_score is later used to subtract highest and lowest score from the variable

    Code:
    #Converts list to int
    def convertToInt(numList):   # [1,2,3]
        s = map(str, numList)   # ['1','2','3']
        s = ''.join(s)          # '123'
        s = int(s)              # 123
        return s
    
    for index in range(len(diver_name)):
          
            #Diver name
            print(diver_name[index], "-", diver_country[index])
            all_scores = []
            total_score = 0
            #Scores
            for scores in randomScore():
              all_scores.append([scores]) // adds the score on to list
              total_score += scores // adds the score to the total_score value
              
            print(all_scores)
    
            #Gets the maximum and minimum
            maximum_score = max(all_scores)
            minimum_score = min(all_scores)
    
    
            #Converts to integer
            maximum_score = convertToInt(maximum_score)
            minimum_score = convertToInt(minimum_score)
    
            #Displays maximum and minimum
            print("Maximum score: %d" %maximum_score)
            print("Minimum score: %d" %minimum_score)
            
            total_score -= maximum_score
            total_score -= minimum_score
    
            #Total
            print("Total score : %d\n" %total_score)
    Regarding displaying the OVERALLSCORE of the divers. I would suggest creating a overall score list and then:

    Here is a way of how you can structure it (Dummy code):
    The curly brackets are there to show you what is inside and outside the loop. (this is not correct python syntax)
    Code:
    overall_score = []; // outside of processing driver loop
    for(process_driver) {
        for(processes_total_score) {
         
        }
    
        overall_score.append([driver_name, total_score]) // inside of processing diver loop
    }
    
    
    
    Winner = find_largest_score(overall_score[]) // you need a function to loop through the scores and find the max() number
    
     //assuming find_larget_score() returns a list, it can be like this ['divername', 123']
    // %s is the diver name %d is the score.
    print(“Diver: %s has won scoring %d”, winner[0], winner[1])
    
    //winner[0] is name and [1] is score.
    I am only trying to give an example. it does not work. The idea is that after the total score for each driver is calculated it is added to the overall score.

    I hope this helps.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 44
    Last Post: 07-22-2015, 04:01 PM
  2. Awesome Tutorial Program
    By purepkownage in forum Downloads
    Replies: 8
    Last Post: 10-30-2010, 10:30 PM
  3. python section in programming
    By Simon in forum Suggestions
    Replies: 2
    Last Post: 01-11-2010, 12:12 PM
  4. Programming for cash - Java / PHP
    By Jeebals in forum RS2 Server
    Replies: 4
    Last Post: 10-29-2007, 10:27 AM
  5. Replies: 12
    Last Post: 07-10-2007, 03:08 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •