Question

P 6.1 page 373, Write a program to initialize a list with 10 random integers from...

P 6.1 page 373, Write a program to initialize a list with 10 random
integers from 0 to 1000(inclusive) and output the following: (10 points)


import random

SEED = int(input("Input seed: "))
random.seed(SEED)

print("\na. Every element at an even index")


print("\nb. Every even element")


print("\nc. All elements in reverse order.")


print("\nd. Only the first and the last element.")

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import random

SEED = int(input("Input seed: "))
random.seed(SEED)

lst = []
for i in range(10):
    lst.append(random.randint(0, 1000))
print("\na. Every element at an even index")
for i in range(len(lst)):
    if i % 2 == 0:
        print(lst[i])

print("\nb. Every even element")
for num in lst:
    if num % 2 == 0:
        print(num)

print("\nc. All elements in reverse order.")
for i in range(len(lst) - 1, -1, -1):
    print(lst[i], end=' ')
print()

print("\nd. Only the first and the last element.")
print(lst[0], lst[-1])

Input seed: 7 a. Every element at an even index 331 154 666 74 548 b. Every even element 970 154 404 666 74 840 548 96 c. All

Add a comment
Know the answer?
Add Answer to:
P 6.1 page 373, Write a program to initialize a list with 10 random integers from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that initializes an array with ten random integers and then prints out the...

    Write a program that initializes an array with ten random integers and then prints out the following: Every element at an even index; Every even element All elements in reverse order; Only the first and last elements; The minimum and maximum element The sum of all elements The alternating sum of all elements, where the alternating sum contains all elements at even index added, and the elements at odd index subtracted. Please write comments above the piece of code that...

  • 6.7 LAB: Guess the random number Given the code that reads a list of integers, complete...

    6.7 LAB: Guess the random number Given the code that reads a list of integers, complete the number_guess() function, which should choose a random number between 1 and 100 by calling random.randint and then output if the guessed number is too low, too high, or correct. Import the random module to use the random seed() and random.randinto functions. • random.seed(seed_value) seeds the random number generator using the given seed_value. • random.randint(a, b) returns a random number between a and b...

  • Write a C++ program with the following functionality. Place the even integers from 10 (inclusive) to...

    Write a C++ program with the following functionality. Place the even integers from 10 (inclusive) to 40 (inclusive) in a queue, Q. Remove the first 10 integers from Q and add to a stack, S. Pop and print all the elements from S.

  • (a) Write a C program to print a list of all integers between 1 and 1,000...

    (a) Write a C program to print a list of all integers between 1 and 1,000 (inclusive) which are divisible by 7 but not by 13. The list should be printed to a file called "output.dat". Remember to close the file after use. (35%) (b) Explain what is meant by the C preprocessor. Explain the effect of the following line of code: #define SQUARE (x) (x) * (x) (25%) (c) Explain the concept of an array in C. Write down...

  • Write a JAVA program with methods that initializes an array with 20 random integers between 1...

    Write a JAVA program with methods that initializes an array with 20 random integers between 1 and 50 and then prints four lines of output, containing 1)The initialized array. 2)Every element at an even index. 3)Every even element. 4)All elements in reverse order. Requirements (and hints): 1. Build a method that takes any integer array as input and prints the elements of the array. ALL printing in this lab must be done using a call to the printArray method and...

  • This program will use the Random class to generate random temperatures (integers) between some minimum (inclusive)...

    This program will use the Random class to generate random temperatures (integers) between some minimum (inclusive) and some maximum (inclusive) values. You will need to calculate the minimum and maximum given a starting temperature integer and a possible change in temperature integer. (1) Copy the following method stub into your Temperature Predictor class and complete it according to the specifications described in the header comments. * Generates a random temperature (int) within a range when given the current temperature *...

  • (+30) Provide a python program which will Populate an array(list) of size 25 with integers in...

    (+30) Provide a python program which will Populate an array(list) of size 25 with integers in the range -100 (negative 100)   to +100 inclusive Display the array and its length (use the len function) Display the average of all the integers in the array Display the number of even integers (how many) Display the number of odd integers (how many) Display the number of integers > 0   (how many) Display the number of integers < 0   (how many) Display the...

  • 2. Write a C++ program, that generates a set of random integers and places them in...

    2. Write a C++ program, that generates a set of random integers and places them in an array. The number of values generated and their range are entered by the user. The program then continually prompts the user for one of the following character commands: a: display all the values I: display the values less than a given value g display the values greater than a given value e: display all odd values o: display all even values q: quit...

  • Write a program that creates a list of 20 integers (between 1 and 40) using a random number generator function. Write a function that returns the index (position) of the third largest element from the...

    Write a program that creates a list of 20 integers (between 1 and 40) using a random number generator function. Write a function that returns the index (position) of the third largest element from the list of integers. If there are more than one third largest number, return the index of the first occurrence of that number. Eg: Assume that your main function has created the following list of integers generated from the random number function. [12, 30, 28, 4,...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT