Question

(((Python))) How can we use a LIST in a sequence or an IF Statement? Do we...

(((Python)))

How can we use a LIST in a sequence or an IF Statement? Do we create a list, like in a Tuple, or can we ask a user for a set of items to add into our list? Give some examples if you can.

Homework Answers

Answer #1

➢ In python we can create a list by putting all the elements inside a square bracket[] separated by a comma

➢ A list can have any type of data (i.e, string, float, integer)

➢ A list can also have a list inside a list

Lists with IF statement:

In the below code shopping is the list and bread, jam, and marmite are the elements of the list

creating a list inside a tuple or vice versa:

➢ we can create a list inside a tuple or a tuple inside a list in python

example:

Taking user input for creating a list:

by using the following code we can take the input of the list from the user:

Know the answer?
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
Similar Questions
For part 1, you will NOT be writing anything in Python. You will be describing how...
For part 1, you will NOT be writing anything in Python. You will be describing how the program will work using words and illustrations if it helps. Using a dictionary, make a text encrypter/decrypter. In decrypt mode, if the user inputs “Y r u l8?”, the program should output “Why are you late?”, for example. In encrypt mode, if the user inputs “See you later”, it should output “c u l8r”. Obviously you can’t handle every possible phrase, but add...
I have the below homework problem for a python programming class, and i really need some...
I have the below homework problem for a python programming class, and i really need some help!! First, take a set of 6 grades from a user and average them. Provide the average to the user. You need to check to make sure the grades are within the normal range. If the grade is less than 0 or more than 100, issue a warning to the user. You don't need to take the grade again, just let the user know....
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items...
Name the script for.sh.  This script will create a shopping list. Ask the user to enter items separated by a space. Read the list. Use a for loop to write (use echo) the items to a file called shopping_list. You should use >> to append the output to the file, so each time the script is run the list should get longer. After the for loop finishes, display (use cat) the contents of the shopping list with 1 item per line....
There are many people who do not look like the people we are familiar with. Some...
There are many people who do not look like the people we are familiar with. Some scientists believe that this "fear of others who look different" stems from our prehistoric days. Our brains said "run" when we met others who did not look the same as us. Use your imagination and ask yourself how would react to someone with hypertrichosis?
** Language Used : Python ** PART 2 : Create a list of unique words This...
** Language Used : Python ** PART 2 : Create a list of unique words This part of the project involves creating a function that will manage a List of unique strings. The function is passed a string and a list as arguments. It passes a list back. The function to add a word to a List if word does not exist in the List. If the word does exist in the List, the function does nothing. Create a test...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci...
In mathematics, the Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and characterized by the fact that every number after the first two is the sum of the two preceding ones: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … The sequence Fn of Fibonacci numbers is defined by the recurrence relation: Fn = Fn-1 + Fn with seed values F1 = 1 F2 = 1 For more information on...
What is a leakage? When do we use a leakage? Please explain and give some examples,...
What is a leakage? When do we use a leakage? Please explain and give some examples, thank you.
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in...
***Python Hailstones, also known as the Collatz sequence, are a mathematical curiosity. For any number in the sequence, the next number in the sequence is determined by two simple rules: If the current number n is odd, the next number in the sequence is equal to 3 * n + 1 If the current number n is even instead, the next number in the sequence is equal to one half of n (i.e., n divided by 2) We repeat this...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm...
HIMT 345 Homework 06: Iteration Overview: Examine PyCharm’s “Introduction to Python” samples for Loops. Use PyCharm to work along with a worked exercise from Chapter 5. Use two different looping strategies for different purposes. Prior Task Completion: 1. Read Chapter 05. 2. View Chapter 05’s video notes. 3. As you view the video, work along with each code sample in PyCharm using the Ch 5 Iteration PPT Code Samples.zip. Important: Do not skip the process of following along with the...
We would like to estimate the mean salary for a given population. In order to do...
We would like to estimate the mean salary for a given population. In order to do that, we would like to take a sample. We want a 95% confidence interval with a margin of error of 400. To estimate the standard deviation of the population, we took a pilot sample, the size of 30, and found the standard deviation of their salaries to be 5000. How many people do we have to ask to create our desired confidence interval (total...