Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Introduction to Computer Programming NAME:_______________________ Lab Exercise #3 Use Python (IDLE) to test your answers to the following lab exercises. 1. Write down the Python programming constructs that produce the desired output. Use IDLE in either interactive mode or script mode to verify your answers. a. Write a single Python statement generates the sequence [0, 2, 4, 6, 8, 10]. b. Write a single Python statement that generates the sequence [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]. c. Write a single Python statement that generates the sequence [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5]. d. Write a for loop that outputs the sequence 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 e. Write a for loop that outputs the sequence 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 f. Write a Python code fragment using for loops that outputs the sequence 1, 2, 6, 24, 120, 720 2. Write a small Python program that reads a string from standard input and displays the length of the string. This will repeat until the input string has a length of zero. 3. Write a Python program that decomposes an input string into a vowel string and an “other” string. Read one string from standard input and loop for every character in the input string. If the string element is a vowel, then concatenate the letter to the vowel string. If the string element is not a vowel, then concatenate the letter to the “other” string. At the end of processing all string elements, print the vowel string and the other string. 4. Using the following tuple days = (“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”) a. Write a Python statement that will print out the week days b. Write a single Python statement that will print out the weekend days. 5. Given the following Python tuple statement, days = (“Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”, “Sun”) Using slicing and concatenation, write the Python statements that would transform the days tuple into the following. days = (“Sun”, “Mon”, “Tue”, “Wed”, “Thu”, “Fri”, “Sat”)