Final Examinaon 20200131
H. Drawing a Graph
Mr. Sugimoto is trying to draw a graph of sine funcon like this.
These funcons are a sine funcon black and its approximaon via Taylor expansions other colors defined by
x3 x5 sinx x
x7 x2k1 1k
3! 5!
7! k0 2k 1!
However, due to many bugs contained in his code, he is geng sick now. Please debug his code to
help him. His incomplete code with some bugs is shown below.
I. Format Numbers
Given a posive number x 0 x 9.999 for each line from standard input, you must print the number to the standard output using the following three formats. For example, if the number is 1 , it should be formaed to
THIS IS INCOMPLET CODE! IT HAS SOME BUGS! by Sugimoto
import math
import numpy as np
import matplotlib.pyplot as plt
Taylor expansion of sine
def approximatesinx,order:
y x.copy
for k in rangeorder:
frac math.factorial2k1
y 1kx2k1frac
return y
I want to make a graph in range 0,2pi
x np.linspace0,360,140
y np.sinx
y1 approximatesinx,1
y3 approximatesinx,3
y5 approximatesinx,5
y7 approximatesinx,7
y9 approximatesinx,9
Set X Y range and its ticks
plt.xlim0,360
plt.ylim1.5,1.5
ticks 0,frac12pi,pi,frac32pi,2pi
plt.xticksnp.linspace0.0,2.0np.pi,5,ticks
Plotting curves
plt.plotx,y1,label1st order
plt.plotx,y3,label3rd order
plt.plotx,y5,label5th order
plt.plotx,y7,label7th order
plt.plotx,y9,label9th order
plt.plotx,y,k,lw2,labely sintheta
Show the graph!!
plt.grid
plt.legendloclower left
plt.tightlayout
plt.show
x 0 x 9.999 3 1
1. always with 2 decimal places 2
2. asa4digitroundoffintegerwithappropriateheading 0 40
Please output the number in one line with comma delimiter. If any negave number is input, please
finish the program.
Sample input
Sample output
1.00
0001
1
0
3.3
9.999
1
1.000,0001
0.000,0000
3.300,0003
9.999,0009
1
J. The Nearest Prime Numbers
z p z
Given an integer z from standard input, answer the nearest prime numbers p. If the nearest prime numbers are not unique, output them in increasing order with space delimiter . You must deal with as a large input number z as you can.
Sample input 1
3
Sample output 2
Sample input 1
4
Sample output 2
35
K. Cleaning Robot
Mr. Sugimoto is planning to buy a cleaning robot. He wants to imagine a cleared room from a real room map before buying it.
A room map is given from standard input and then output the cleaned room map aer the robot runs to standard output.
The specificaon of room map is detailed as follows. The room is a rectangle at most 70mes70 cells, given as a sequence of strings. means a wall, . means a dirty floor, means a clean floor and means the inial posion of the robot.
The four edges of the room is occupied by walls . The robot can move the four direcons NSE W direcons but cannot move onto wall . In the first situaon, all the floors are dirty. An empty line from input means terminaon of room map input.
70mes70 . , 4
Sample input 1
…..
……
……
3
Sample output 1
Sample input 2
………….
..
……….
……….
……….
Sample output 2
…. .. …. .. …. ..