C:pythonPython Programmingweek 5
1. 1. A palindrome is a word or a phrase that reads the same way backwards as forwards. Write a function that accepts a text string as input and determines whether or not the text string is a palindrome. Then write a program “Lab5B” that uses this function. Prompt the user to enter a word or phrase and then inform the user whether or not the text entered qualifies as a palindrome. [Hint: there is a REVERSE method for a string. But to compare a string reversed this way, you need to convert to list: if list(str) == list(rev_str):] 2. 1. Write a Python program (its name must be “Lab5B”) that generates a sequence/list of unique prime numbers (a prime number is only evenly divisible by itself and 1, for example, 5, 7, 11, 13 are prime numbers). Specifically, the program must meet the following detailed requirements: 1. Define a function, is_prime(n), which return True if n is a prime number, otherwise return False. 2. Define a function, generate_random_number(n1, n2), which return a prime number that is between n1 and n2 inclusive. (Hint: use nt(n1, n2) to generate a random number). Define a function, number_of_primes_in_the_range(n1, n2), which return the total number of prime numbers in the range [n1, n2]. The program must first read input of 3 integers in a single line (i.e., a string consisting of 3 integers separated by space): a. the first integer defines the number of prime numbers to be generated; b. the second and third integers inclusive defines the range of those prime numbers; c. the program must check the 3 integers to make sure these integers are provided correctly; if not, the program must keep reading and checking the input to make sure they are correct—use the following demo outputs for your reference; d. the program may not read the 3 integers one by one; e. (hints: use the above defined function number_of_primes_in_the_range(n1, n2) to examine whether the 1st integer in the input is correct.) f. (hints: you may find the example given at The program outputs the sequence/list of unique prime numbers as defined by the input with use of the above defined functions. The program outputs the prime number in reversed order, sorted order, and finally the minimum and maximum prime numbers—use the following demos as your design and implementation of this project.
Written for
- Institution
- Python Programming
- Course
- Python Programming
Document information
- Uploaded on
- July 22, 2023
- Number of pages
- 3
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
pythonprogrammingweek5
Also available in package deal