Question

Use Python Spyder to answer: First List – Loop (one that you created in lab 1...

Use Python Spyder to answer:

First List – Loop (one that you created in lab 1 or any new list)

• Repeat First List, but this time use a loop to print out each value in the list.

First Neat List - Loop

• Repeat First Neat List, but this time use a loop to print out your statements. Make sure you are writing the same sentence for all values in your list. Loops are not effective when you are trying to generate different output for each value in your list.

Your First List - Loop

• Repeat Your First List, but this time use a loop to print out your message for each item in your list. Again, if you came up with different messages for each value in your list, decide on one message to repeat for each value in your list.

Exercises Working List

• Make a list that includes four careers, such as 'programmer' and 'truck driver'.

• Use the list.index() function to find the index of one career in your list.

• Use the in function to show that this career is in your list.

• Use the append() function to add a new career to your list. • Use the insert() function to add a new career at the beginning of the list.

• Use a loop to show all the careers in your list.

Starting From Empty

• Create the list you ended up with in Working List, but this time start your file with an empty list and fill it up using append() statements.

• Print a statement that tells us what the first career you thought of was.

• Print a statement that tells us what the last career you thought of was.

Ordered Working List

• Start with the list you created in Working List.

• You are going to print out the list in a number of different orders.

• Each time you print the list, use a for loop rather than printing the raw list.

• Print a message each time telling us what order we should see the list in.

o Print the list in its original order.

o Print the list in alphabetical order.

o Print the list in its original order.

o Print the list in reverse alphabetical order.

o Print the list in its original order.

o Print the list in the reverse order from what it started.

o Print the list in its original order

o Permanently sort the list in alphabetical order, and then print it out.

o Permanently sort the list in reverse alphabetical order, and then print it out.

Ordered Numbers

• Make a list of 5 numbers, in a random order.

• You are going to print out the list in a number of different orders.

• Each time you print the list, use a for loop rather than printing the raw list.

• Print a message each time telling us what order we should see the list in.

o Print the numbers in the original order.

o Print the numbers in increasing order.

o Print the numbers in the original order.

o Print the numbers in decreasing order.

o Print the numbers in their original order.

o Print the numbers in the reverse order from how they started.

o Print the numbers in the original order.

o Permanently sort the numbers in increasing order, and then print them out.

o Permanently sort the numbers in descreasing order, and then print them out.

List Lengths

• Copy two or three of the lists you made from the previous exercises, or make up two or three new lists.

• Print out a series of statements that tell us how long each list is.

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

list1 = [i for i in range(0,12)]#crearting the new list
list1
for element in list1: #here element refers to each and every element of the list
print(element)
for element in list1:
print("testing")#instead of testing one can write anything else according to one's choice
career = ['programmers','truck driver','doctor','engineer']
print(career.index('doctor'))# It will show index 2 because index starts from 0 in python
career.append('chef')# chef will be appended into the list.
#chef is to be written either in single quotes or in double one's
print(career)
career.insert(0,'Manager')#as index starts from 0. It will insert Manager at beginning of the list
print(career)
for careers in career:
print(careers)
WorkingList = [] # starting from empty list
WorkingList.append("Manager")
WorkingList.append("Tester") #SImilarly you can write multiple careers
WorkingList.append("Designer")
WorkingList.append("Truck Driver")
WorkingList.append("Doctor")
print(WorkingList)

print("I firstly thought of a "+WorkingList[0]) #Prints the 0th element and + sign is for concatenation

print("Then I thought of a "+WorkingList[1])

print(sorted(WorkingList)) #Sorted Function for sorting without the actual change in the list

print(WorkingList)

print(sorted(WorkingList,reverse=True))# Reverse = True means sorting in reverse order

print(WorkingList)

#for permanent sorting
WorkingList.sort()
print(WorkingList)

#In Reverse order
WorkingList.sort(reverse=True)
print(WorkingList)

import random
list2 = []
for i in range(0,5): # for looping for 5 times
n = random.randint(1,30) #for creating random numbers
list2.append(n)

print(list2)

print(sorted(list2))

print(sorted(list2))

print(list2)

print(sorted(list2,reverse=True))

print(list2)

list2.sort()
print(list2)

list2.sort(reverse=True)
print(list2)

print("list1 is of length ",len(list1)) #Now we use , because len will give number and other text is string
# So we cannot concatenate String with number

print("list2 is of length ",len(list2))

print("WorkingList is of length ",len(WorkingList))

Add a comment
Know the answer?
Add Answer to:
Use Python Spyder to answer: First List – Loop (one that you created in lab 1...
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
  • **C++ only, use standard library, no vectors Write a program to generate a list of 5000...

    **C++ only, use standard library, no vectors Write a program to generate a list of 5000 random numbers between 1 and 10,000 stored in an array. Sorts: Print out the middle 50 numbers of the original list to show the results. Now sort the original numbers using bubble sort. Print out the number of swaps made. Now sort the original numbers using selection sort. Print out the number of swaps made. Now sort the original numbers using insertion sort. Print...

  • Python Question? Write a function called reverse(user_list, num = -1) that takes a list and a...

    Python Question? Write a function called reverse(user_list, num = -1) that takes a list and a number as parameters. The function returns a copy of the list with the first number of items reversed. Conditions: The number parameter must be a default argument. -      If the default argument for number is given in the function call, only the first number of items are reversed. -      If the default argument for number is not provided in the function call, then the...

  • Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a...

    Python Help Please Problem 4-4: Make a list of 20 numbers and place them in a random order (don't arrange them in ascending or descending order - make sure the list is truly random). Calculate and print out the largest number in the list and the lowest number in the list. Problem 4-5: Make a list of multiples of 5 between 1 and 100. Once you have your list, print it out. Problem 4-6: Generate a list of values from...

  • Create a new Python program in IDLE, and save it as lab8.py.(Again, I recommend saving lab...

    Create a new Python program in IDLE, and save it as lab8.py.(Again, I recommend saving lab progranms Your Python program will do the following: Create an empty list . Use a for loop to ask the user for 10 numbers. Add each number to your list using the append metha . Use another for loop to print the list in reverse order, one per line . Use a while loop to count how many positive numbers are in the list...

  • I need to write a Python Program for the following question. Link for tallest mountains: https://en.wikipedia.org/wiki/List_of_mountains_by_elevation Use top 10 tallest mountains. Part One Wikipedia...

    I need to write a Python Program for the following question. Link for tallest mountains: https://en.wikipedia.org/wiki/List_of_mountains_by_elevation Use top 10 tallest mountains. Part One Wikipedia has a list of the tallest mountains in the world each mountain's elevation. Pick 10 mountains from this list. Create a dictionary with the mountain names as keys, and the elevations as values. Print out just the mountains' names, by looping through the keys of your dictionary. Print out just the mountains' elevations, by looping through...

  • write a java program that does the following Part one Use a For loop to compute...

    write a java program that does the following Part one Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic (Nested loops: Indent text) so that the...

  • Python program - Write a Python program, in a file called sortList.py, which, given a list...

    Python program - Write a Python program, in a file called sortList.py, which, given a list of names, sorts the names into alphabetical order. Use a one dimensional array to hold the list of names. To do the sorting use a simple sorting algorithm that repeatedly takes an element from the unsorted list and puts it in alphabetical order within the same list. Initially the entire list is unsorted. As each element is placed in alphabetical order, the elements in...

  • (+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...

  • Your Python program should perform the following three tasks: 1. After getting a word of input...

    Your Python program should perform the following three tasks: 1. After getting a word of input from the user (i.e., any string), your program should use a while (or for) loop to print out each of the letters of the word. Just remember that strings in Python start with element 0! 2. Your program should then use another loop to print out each of the letters of the (same) word in reverse order! 3. Ask the user for a letter...

  • Piggy back on the programming project one you completed in module 3. You will use some...

    Piggy back on the programming project one you completed in module 3. You will use some of those concepts here again. We will be building this project inside out, start individual quiz and use a for loop to repeat it three times for three students. In this program you will be required to write a python program that generates math quizzes for students in second grade. Your program should do the following Ask the student for their name Provide 3...

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