Question: Python: Write a program ranges.py in three parts. (Test after each added part.) This problem is not a graphics program . It is just a
Python:
Write a program ranges.py in three parts. (Test after each added part.)
This problem is not a graphics program. It is just a regular text program to illustrate your understanding of ranges and loops.
For simplicity each of the requested number sequences can just be printed with one number per line. Print a label for each number sequence before you print the sequence, like Numbers 1-4, Numbers 1-n, Five random numbers in 1-n.
First use the range function and a for-loop to produce the sequence 1, 2, 3, 4, and then print the numbers, one number per line.
Prompt the user to input an integer n and print the sequence 1, 2, 3, ... , n - including n, using a for-loop. Hint: [4]
Use a Simple Repeat Loop to find and print five randomly chosen numbers from the range 1, 2, 3, ... , n. Use the same value of n that the user chose earlier in the program. It should be possible that the number n is printed sometimes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
