CS115_Lab02
CS115_Lab02
Lab 02
Lab Objectives: Strings, Loops, Nested Loops.
Q1: Write a program Lab02_Q1.py to input a positive integer n and displays the sum of the
first n terms of the sequence: In other words, the program should generate the following
sequence: 1 + (1/2) + (1/3) + (1/4) + (1/5) + ... + (1/n)
Assume that the input n is positive. The sum of the fractions should be displayed in 3 digits
after the decimal point.
Q2: Write a program Lab02_Q2.py to input two integers and print the sequence of integers
between the two input integers, separated by commas and enclosed in square brackets. Display an
increasing sequence if the first argument is smaller than the second; otherwise, display a
decreasing sequence. If the two numbers are the same, that number should be displayed by itself.
Sample Run:
Enter the first integer: 115
Sample Run:
Enter a string (exit to stop): abccdddd
adjacent duplicates removed: abcd