Q. Write a program to read following details of sports' performance (sport, competitions, prizes-won) of your school and store into a csv file delimited with tab character.
Answer :-
import csv fh = open("Sport.csv", "w") swriter = csv.writer (fh, delimiter = '\t') swriter.writerow( ["Sport", "Competitions", 'Prizes won']) ans = 'y' i = 1 while ans == "y": print("Record", i) sport = input ("Sport name: ") comp = int(input("No. of competitions participated: ")) prizes = int(input("Prizes won: ")) srec = [ sport, comp, prizes ] swriter.writerow(srec) i = i + 1 ans = input("Want to enter more records? (y/n).. ") fh.close()
Output :-
Record 1
Sport name: Tennis
No. of competitions participated: 9
Prizes won: 3
Want to enter more records? (y/n).. y
Record 2
Sport name: Football
No. of competitions participated: 6
Prizes won: 4
Want to enter more records? (y/n).. y
Record 3
Sport name: Chess
No. of competitions participated: 8
Prizes won: 6
Want to enter more records? (y/n).. n
>>>
The file contain data like :-
Sport Competitions Prizes won
Tennis 9 3
Football 6 4
Chess 8 6
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )