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
The last thing we will learn about in python is functions. Functions are a great way...
The last thing we will learn about in python is functions. Functions are a great way to organize your program - we use them to write code that is executed only under certain circumstances - for instance when you're using Amazon, any of the following are likely functions within their program: - Add item to cart, determine arrival date,  create a new address, compute taxes, compute shipping charges, charge credit card Because you can write a task-specific function once, and ensure...
Write a Python program to ask how many elements do users want to create in a...
Write a Python program to ask how many elements do users want to create in a list, then let the user create 2 lists with the number of elements previously entered. Then create and display all combinations of letters, selecting each letter from a different key in a dictionary. Example: How many elements? 2 List 1 = ['a', 'b'] List 2 = ['c', 'd'] Output: ac ad bc bd
In python.....Create a Linked List program using at least 15 items. Must use the following in...
In python.....Create a Linked List program using at least 15 items. Must use the following in your program: Min() Max() Index() Count() Remove() Note: Use the "print" statement after each method.
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes...
Challenge: Animal Class Description: Create a class in Python 3 named Animal that has specified attributes and methods. Purpose: The purpose of this challenge is to provide experience creating a class and working with OO concepts in Python 3. Requirements: Write a class in Python 3 named Animal that has the following attributes and methods and is saved in the file Animal.py. Attributes __animal_type is a hidden attribute used to indicate the animal’s type. For example: gecko, walrus, tiger, etc....
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression...
(For Python) Evaluating Postfix Arithmetic Expressions. In this project you are to implement a Postfix Expression Evaluator as described in section 7-3b of the book. The program should ask the user for a string that contains a Postfix Expression. It should then use the string's split function to create a list with each token in the expression stored as items in the list. Now, using either the stack classes from 7.2 or using the simulated stack functionality available in a...
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...
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?
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....
   QUESTION 6 1.   If we wanted something like the python else statement for a counter...
   QUESTION 6 1.   If we wanted something like the python else statement for a counter controlled loop in Java, what would it look like?        Since there is no way for a loop in Java to tell you if it completed without breaks or continues, you'd need to set a boolean flag to indicate that and check it after the loop was completed.        We simply check either break or continue flags to see if either is...
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.