For more codes click here
#check data type for all elements in a list
a = [1,"pease", 4, "dog"]
for i in a:
if isinstance(i, int):
print(f"{i} is an integer")
elif isinstance(i, str):
print(f"{i} is a string")
else:
pass
Climb up the chart of development, from web, to software and games. Build your foundations and get certified. Let me help you get your first tech job.
For more codes click here
#check data type for all elements in a list
a = [1,"pease", 4, "dog"]
for i in a:
if isinstance(i, int):
print(f"{i} is an integer")
elif isinstance(i, str):
print(f"{i} is a string")
else:
pass
from re import sub
In this game, two players sit in front of a pile of 100 stones. They take turns, each removing between 1 and 5 stones (assuming there are at least 5 stones left in the pile). The person who removes the last stone(s) wins.
Write a program to play this game. This may seem tricky, so break it down into parts. Like many programs, we have to use nested loops (one loop inside another).
In the outermost loop, we want to keep playing until we are out of stones.
Inside that, we want to keep alternating players. You have the option of either writing two blocks of code, or keeping a variable that tracks the current player. The second way is slightly trickier since we haven't learned lists yet, but it's definitely do-able!
Finally, we might want to have an innermost loop that checks if the user's input is valid. Is it a number? Is it a valid number (e.g. between 1 and 5)? Are there enough stones in the pile to take off this many? If any of these answers are no, we should tell the user and re-ask them the question.
So, the basic outline of the program should be something like this:
TOTAL = 100
MAX = 5
pile = TOTAL # all stones are in the pile to start
while [pile is not empty]:
while [player 1's answer is not valid]:
[ask player 1]
[check player 1's input... is it valid?]
[same as above for player 2]
Note how the important numbers 100 and 5 are stored in a single variable at the top. This is good practice -- it allows you to easily change the constants of a program. For example, for testing, you may want to start with only 15 or 20 stones.
Be careful with the validity checks. Specifically, we want to keep asking player 1 for their choice as long as their answer is not valid, BUT we want to make sure we ask them at least ONCE. So, for example, we will want to keep a variable that tracks whether their answer is valid, and set it to False initially.
When you're finished, test each other's programs by playing them!
Write a program that first displays a simple cafe menu (see example below), asks the user to enter the number of a choice, and either prints the appropriate action OR prints an error message that their choice was not valid.
Example output:
1. Soup and salad
2. Pasta with meat sauce
3. Chef's special
Which number would you like to order? 2
One Pasta with meat sauce coming right up!
Another example output:
1. Soup and salad
2. Pasta with meat sauce
3. Chef's special
Which number would you like to order? 5
Sorry, that is not a valid choice
Given a string as input, use recursion to output each letter of the strings in reverse order, on a new line.
Sample Input
HELLO
Sample Output
O
L
L
E
H
You are working at a car dealership and store the car data in a dictionary:
car = {
'brand': 'BMW',
'year': 2018,
'color': 'red'
}
Your program needs to take the key as input and output the corresponding value.
Sample Input
year
Sample Output
2018
A namespace is a collection of names and the details of the objects that the names refer to.
PIP is a package management system that is used to install and manage Python-based software packages.
For those of you who don't know, oop stands for Object-Oriented Programming. Is python an oop, and why?
Function is a collection of operations which can be easily accessed throughout a program. these operation accepts a variable and passes it through the stated operations to give an output.
Loops are used to iterate within a set of variables. This can either be a list, string, tuple etc.
Headings
HTML has 6 main categories of heading tags which varies in sizes which decreases as the number gets higher.
Saving your HTML file
All files are saved with extensions which helps to determine how they are ran.
HTML files are saved with .html