We propose a method to obtain the refractive index of a transparent sphere from the fascinating phenomena of rainbows, which can be used as an interesting subject in the experimental courses of primary optics for undergraduate or high school students. The primary and secondary rainbows are reproduced on white walls and screens in the classroom with the sun and water drops replaced by the LED flashlight and K9 glass (one type of borosilicate glass) sphere respectively. The locations of the primary and secondary rainbows on the screen are measured, with the locations of the screen and sphere changed. By fitting the multiple measurements to the theoretical result using the least square method, the refractive index of the glass sphere, as an unknown parameter in the fitting process, is obtained. For both the primary and secondary rainbows, the locations of the red, yellow and purple bows are measured independently. Repetitive measurements give very stable and accurate output with the standard deviation ratio as low as 10−4 and the relative error all around 0.1% compared to the result obtained from special instruments in the literature. The fascinating phenomena and precise measurements enable this method to fully deepen the students’ understanding of the law of refraction and the application of the least square method.