Page 163 - TP_V5.1_C8_fb
P. 163

6.  Do as directed.                                                                            4×2.5=10
                    a. Write a Python program to print the following series:

                      1 4 7 10 ........... 40.
                    b. Write a Python script that prompts the user to input a length in centimeters. If the user enters
                       a negative value, the program should display a message indicating that the entry is invalid.
                       Otherwise, it should convert the length to inches and display the result. (Note: 1 inch equals 2.54
                       centimeters.)
                    c. Write a Python script to get the following output:

                      5 × 1 = 5
                      5 × 2 = 10
                      5 × 3 = 15

                      5 × 4 = 20
                      5 × 5 = 25

                    d. Write a Python script to solve the following quadratic equation:
                          2
                      ax  + bx + c = 0.
                      where the values of a, b, c, and x are 5, 4, 3, and 7.






















































                                                                                   Half-Yearly Examination Sample Paper  161
   158   159   160   161   162   163   164   165   166