8th day of python challenges 111-117

This commit is contained in:
abd.shallal
2019-08-04 15:26:35 +03:00
parent b04c1b055f
commit 627802c383
3215 changed files with 760227 additions and 491 deletions

View File

@@ -0,0 +1,6 @@
To Kill A Mockingbird, Harper Lee, 1960
A Brief History of Time, Stephan Hawking, 1988
The Man Who Mistook His Wife for a Hat, F.Scott Fitzerald, 1922
Pride and Prejudice, Jane Austen, 1813
my life through shit, abdullah shallal, 2020
just do it, abdullah shallal, 1933
1 To Kill A Mockingbird Harper Lee 1960
2 A Brief History of Time Stephan Hawking 1988
3 The Man Who Mistook His Wife for a Hat F.Scott Fitzerald 1922
4 Pride and Prejudice Jane Austen 1813
5 my life through shit abdullah shallal 2020
6 just do it abdullah shallal 1933

View File

@@ -0,0 +1 @@
abdullah, 115, 118, 115, 115
1 abdullah 115 118 115 115

View File

@@ -0,0 +1,5 @@
with open('Books.csv', 'w') as file:
file.write('To Kill A Mockingbird' + ', ' + 'Harper Lee' + ', ' + '1960\n')
file.write('A Brief History of Time' + ', ' + 'Stephan Hawking' + ', ' + '1988\n')
file.write('The Man Who Mistook His Wife for a Hat' + ', ' + 'F.Scott Fitzerald' + ', ' + '1922\n')
file.write('Pride and Prejudice' + ', ' + 'Jane Austen' + ', ' + '1813\n')

View File

@@ -0,0 +1,16 @@
file_read = open('Books.csv', 'r')
for row in file_read:
print(row)
file_read.close()
ask_name = str(input('Enter Book Name : '))
ask_author = str(input('Enter Book Author : '))
ask_year = str(input('Enter Book Year Released : '))
file_write = open('Books.csv', 'a')
file_write.write(ask_name + ', ' + ask_author + ', ' + ask_year + '\n')
file_write.close()
file_read_last = open('Books.csv', 'r')
for row in file_read_last:
print(row)
file_read_last.close()

View File

@@ -0,0 +1,21 @@
file_read = open('Books.csv', 'r')
for row in file_read:
print(row)
file_read.close()
ask_count_books = int(input('Enter how many books you want to add to file : '))
for i in range(ask_count_books):
ask_name = str(input('Enter Book Name : '))
ask_author = str(input('Enter Book Author : '))
ask_year = str(input('Enter Book Year Released : '))
file_write = open('Books.csv', 'a')
file_write.write(ask_name + ', ' + ask_author + ', ' + ask_year + '\n')
file_write.close()
ask_author_to_show = str(input('Enter Book Author to show : '))
file_read = open('Books.csv', 'r')
for row in file_read:
if ask_author_to_show in row:
print(row)
file_read.close()

View File

@@ -0,0 +1,17 @@
import csv
file_read = open('Books.csv', 'r')
for row in file_read:
print(row)
file_read.close()
start_year = int(input('Enter start year : '))
end_year = int(input('Enter end year : '))
tmp = []
file_read = open('Books.csv', 'r')
file_reader = csv.reader(file_read)
for row in file_reader:
if start_year < int(row[2]) < end_year:
print(row)
file_read.close()

View File

@@ -0,0 +1,6 @@
file_read = open('Books.csv', 'r')
count_row = 0
for row in file_read:
print('Row ' + str(count_row) + ' : '+row)
count_row += 1
file_read.close()

View File

@@ -0,0 +1,40 @@
import csv
file_read = list(csv.reader(open('Books.csv')))
count_row = 0
list = []
for row in file_read:
print('Row ' + str(count_row) + ' : ' + str(row))
list.append(row)
count_row += 1
ask = int(input('Enter row number to delete : '))
list.pop(ask)
count_row = 0
for row in list:
print('Row ' + str(count_row) + ' : ' + str(row))
count_row += 1
ask = int(input('Enter row number to edit : '))
print('1) Edit book name')
print('2) Edit author')
print('3) Release Year ')
selection_input = int(input('Make a selection 1, 2 or 3 : '))
if selection_input == 1:
ask_name = str(input('Enter Book Name : '))
list[ask][0] = ask_name
elif selection_input == 2:
ask_author = str(input('Enter Book Author : '))
list[ask][1] = ask_author
elif selection_input == 3:
ask_year = str(input('Enter Book Year Released : '))
list[ask][2] = ask_year
i = 0
file_write = open('Books.csv', 'w')
for row in range(len(list)):
file_write.write(list[i][0] + ', ' + list[i][1] + ', ' + list[i][2] + '\n')
i += 1
file_write.close()

View File

@@ -0,0 +1,23 @@
import csv
import random
score = 0
ask_name = str(input('Enter your name : '))
qustion_1_num_1 = random.randint(1, 100)
qustion_1_num_2= random.randint(1, 100)
answer_1 = qustion_1_num_1 + qustion_1_num_2
ask_answer_1 = int(input(str(qustion_1_num_1) + '+' + str(qustion_1_num_2) + '= '))
if answer_1 == ask_answer_1:
score += 1
qustion_2_num_1 = random.randint(1, 100)
qustion_2_num_2 = random.randint(1, 100)
answer_2 = qustion_2_num_1 + qustion_2_num_2
ask_answer_2 = int(input(str(qustion_2_num_1) + '+' + str(qustion_2_num_2) + '= '))
if answer_2 == ask_answer_2:
score += 1
file = open('QuizScore.csv', 'a')
file.write(ask_name + ', ' + str(ask_answer_1) + ', ' + str(answer_1) + ', ' + str(ask_answer_2) + ', ' + str(answer_2) + '\n')
file.close()

View File

@@ -0,0 +1,3 @@
name,address,date joined
john smith,1132 Anywhere Lane Hoboken NJ, 07030,Jan 4
erica meyers,1234 Smith Lane Hoboken NJ, 07030,March 2

View File

@@ -0,0 +1,3 @@
name,department,birthday month
John Smith,Accounting,November
Erica Meyers,IT,March

View File

@@ -0,0 +1,2 @@
John Smith,Accounting,November
Erica Meyers,IT,March
1 John Smith Accounting November
2 Erica Meyers IT March

View File

@@ -0,0 +1,3 @@
emp_name,dept,birth_month
John Smith,Accounting,November
Erica Meyers,IT,March
1 emp_name dept birth_month
2 John Smith Accounting November
3 Erica Meyers IT March

View File

@@ -0,0 +1,6 @@
Graham Chapman,03/15/14,50000.00,10
John Cleese,06/01/15,65000.00,8
Eric Idle,05/12/14,45000.00,10
Terry Jones,11/01/13,70000.00,3
Terry Gilliam,08/12/14,48000.00,7
Michael Palin,05/23/13,66000.00,8
1 Graham Chapman 03/15/14 50000.00 10
2 John Cleese 06/01/15 65000.00 8
3 Eric Idle 05/12/14 45000.00 10
4 Terry Jones 11/01/13 70000.00 3
5 Terry Gilliam 08/12/14 48000.00 7
6 Michael Palin 05/23/13 66000.00 8

View File

@@ -0,0 +1,7 @@
Name,Hire Date,Salary,Sick Days remaining
Graham Chapman,03/15/14,50000.00,10
John Cleese,06/01/15,65000.00,8
Eric Idle,05/12/14,45000.00,10
Terry Jones,11/01/13,70000.00,3
Terry Gilliam,08/12/14,48000.00,7
Michael Palin,05/23/13,66000.00,8
1 Name Hire Date Salary Sick Days remaining
2 Graham Chapman 03/15/14 50000.00 10
3 John Cleese 06/01/15 65000.00 8
4 Eric Idle 05/12/14 45000.00 10
5 Terry Jones 11/01/13 70000.00 3
6 Terry Gilliam 08/12/14 48000.00 7
7 Michael Palin 05/23/13 66000.00 8

View File

@@ -0,0 +1,7 @@
Employee,Hired,Salary,Sick Days
Graham Chapman,2014-03-15,50000.0,10
John Cleese,2015-06-01,65000.0,8
Eric Idle,2014-05-12,45000.0,10
Terry Jones,2013-11-01,70000.0,3
Terry Gilliam,2014-08-12,48000.0,7
Michael Palin,2013-05-23,66000.0,8
1 Employee Hired Salary Sick Days
2 Graham Chapman 2014-03-15 50000.0 10
3 John Cleese 2015-06-01 65000.0 8
4 Eric Idle 2014-05-12 45000.0 10
5 Terry Jones 2013-11-01 70000.0 3
6 Terry Gilliam 2014-08-12 48000.0 7
7 Michael Palin 2013-05-23 66000.0 8

View File

@@ -0,0 +1,59 @@
import csv
# --------- READING CSV ----------
# 1 - Built-in CSV Library
# here return an array --> ['John Smith', 'Accounting', 'November']
with open('employee_birthday.txt') as csv_file:
csv_reader = csv.reader(csv_file)
count = 0
for row in csv_reader:
print(row)
# if count == 0:
# print(f'Columns are {", ".join(row)}')
# count += 1
# else:
# print(f'\t{row[0]} works in the {row[1]} department, and was born in {row[2]}.')
# count += 1
print(f'Processed {count} lines.')
# 2 - Reading CSV Files Into a Dictionary
# return dictionary of arrays --> [('name', 'John Smith'), ('department', 'Accounting'), ('birthday month', 'November')]
with open('employee_birthday.txt') as csv_file:
csv_reader = csv.DictReader(csv_file)
count = 0
for row in csv_reader:
print(row)
# if count == 0:
# print(f'Column names are {", ".join(row)}')
# count += 1
# print(f'\t{row["name"]} works in the {row["department"]} department, and was born in {row["birthday month"]}.')
# count += 1
print(f'Processed {count} lines.')
# --------- WRITING CSV ----------
# 1 - Built-in CSV Library
with open('employee_file.csv', mode='w') as employee_file:
employee_writer = csv.writer(employee_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
employee_writer.writerow(['John Smith', 'Accounting', 'November'])
employee_writer.writerow(['Erica Meyers', 'IT', 'March'])
# 2 - Reading CSV Files Into a Dictionary
with open('employee_file2.csv', mode='w') as csv_file:
fieldnames = ['emp_name', 'dept', 'birth_month']
writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'emp_name': 'John Smith', 'dept': 'Accounting', 'birth_month': 'November'})
writer.writerow({'emp_name': 'Erica Meyers', 'dept': 'IT', 'birth_month': 'March'})

View File

@@ -0,0 +1,32 @@
import pandas
# --------- READING CSV ----------
df = pandas.read_csv('hrdata.csv')
print(df)
df = pandas.read_csv('hrdata.csv', index_col='Name')
print(df)
df = pandas.read_csv('hrdata.csv', index_col='Name', parse_dates=['Hire Date'])
print(df)
dfNh = pandas.read_csv('hrdata-noheader.csv',
index_col='Employee',
parse_dates=['Hired'],
header=0,
names=['Employee', 'Hired', 'Salary', 'Sick Days'])
print(dfNh)
# --------- WRITING CSV ----------
df = pandas.read_csv('hrdata.csv',
index_col='Employee',
parse_dates=['Hired'],
header=0,
names=['Employee', 'Hired', 'Salary', 'Sick Days'])
df.to_csv('hrdata_modified.csv')