Python Exercises
Simple
- Write a program that prints ‘Hello World’ to the screen.
- Write a program that asks the user for their name and greets them with their name.
- Modify the previous program such that only the users Alice and Bob are greeted with their names.
- Write a program that asks the user for a number n and prints the sum of the numbers 1 to n.
- Modify the previous program so that it uses a function called sum_numbers.
- Write a program that asks for the radius of a circle and calculates its area (use the math module to get PI: math.pi).
Lists
- Write a function that returns the largest element in a list.
- Write a function that reverses a list.
- Write a function that checks whether an element occurs in a list.
- Write a function that computes the sum of all elements of a list.
Database
Start by saving the following data into a CSV file called employees.csv.
21,"William",1400,1,3
22,"Evelyn",1600,2,7
23,"Jackson",900,3,11
24,"Ella",750,4,13
25,"Harper",2000,5,17
Using the employees database:
- Write a program that read this CSV file and stores it into the employees table.
- Write a program that writes into a salaries.csv file the average salary of each department (id, name, average).
- Write a program that asks the user for a filename and a department id and writes into the file all the employee data from that department in CSV format.