Developed by Mark Bakker
Write a function that plots a square centered at the origin. The length of the side of the square is $L$. The input of the function is the length $L$.
Next, write a loop that calls your function for $L$ going from 1 up to and including 5 with steps of 1.
Use plt.axis('scaled')
to make sure your squares look like squares and not rectangles.
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
Write a function called countsquares
that takes as input the filename of a file that consists of a bunch of numbers separated by spaces. Inside the function, you must first read the numbers from the filename and then you must determine how many of these numbers are a perfect square. A perfect square means that the root of the number is an integer (i.e., 1, 4, 16, 25, etc.). The function returns the number of perfect squares in the file. Note: to convert a number to an integer, use the int
function.
Demonstrate that your function works by using the file numbers2016.txt
and execute the following line of code:
print(countsquares('numbers2016.txt'), 'numbers are perfect squares')
The file quiz_answers.dat
contains the result of a small multiple-choice quiz with 8 questions. Every row contains the 8 answers to the quiz of one of the students. Your job is to count how many students had the correct answer for each question. Write a double loop to compute the number of correct answers for each question and present the results in a bar graph. The correct answers for the 8 questions of the quiz are: a b c d a b c d
Create the flag of Norway as shown in the figure below.
Create an array of size 40 by 55. Fill the array with zeros, ones and two-s to represent the blue, white, and red parts, respectively. You may only use a maximum of 5 assignment statements to set the correct values for the colors. Make sure you plot the flag using the colormap bwr
(which stands for blue-white-red).
Write a function that computes the percentage of grades that is above a given value. The function takes as input arguments an array with grades between 1 and 10 and a minimum value and returns the precentage of grades (so between 0% and 100%) that are above or equal to that value. Demonstrate that your function works by loading the grades in the file schoolgrades2016.txt
and print the result of the function to the screen with two decimal places, given a minimum value of 7.
You probably know what this should look like
93
Q1: 4, Q2: 4, Q3: 5, Q4:3, Q5:5, Q6:5, Q7:4, Q8:4
Your graph should look like the provided figure
31.3