June 2024
Intermediate to advanced
488 pages
9h 29m
English
Create a Python list of the first ten prime numbers and then use slicing to obtain the 3rd to 7th prime numbers from the list.
Solution:
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
subset_primes = primes[2:7]
print(subset_primes) # Output: [5, 7, 11, 13, 17]
Create a set of vowels and then determine if the letter 'a' and letter 'b' are in the set.
Solution:
vowels = {'a', 'e', 'i', 'o', 'u'}
print('a' in vowels) # Output: True
print('b' in vowels) # Output: False
Define a dictionary that stores the atomic number (as the key) and symbol (as the value) for the elements Hydrogen, Helium, and Carbon. Fetch the symbol for Helium.
Solution:
elements = {
1: 'H', # Hydrogen
2: 'He', # Helium ...
Read now
Unlock full access